Javascript Reference - HTML DOM Input FileUpload autofocus Property








The autofocus property sets or gets whether a file upload button can automatically get focus when the page loads.

Browser Support

autofocus Yes 10.0 Yes Yes Yes

Syntax

Return the autofocus property.

var v = fileuploadObject.autofocus 

Set the autofocus property.

fileuploadObject.autofocus=true|false

Property Values

Value Description
true|false Set whether a file upload button should get focus when the page loads
  • true - The file upload button gets focus
  • false - Default. The file upload button does not get focus




Return Value

A Boolean type value, true if the file upload button automatically gets focus when the page loads, otherwise false.

Example

The following code shows how to get if a file upload button can automatically get focus upon page load.


<!DOCTYPE html>
<html>
<body>
<!--   w w  w .j a  va  2s . com-->
<input type="file" id="myFile" autofocus>
<p id="demo"></p>

<button onclick="myFunction()">test</button>

<script>
function myFunction() {
    var x = document.getElementById("myFile").autofocus;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: