Find out if a file upload button automatically gets focus on page load:
var x = document.getElementById("myFile").autofocus;
Click button to find out if the file upload button automatically gets focus on the page load.
<!DOCTYPE html> <html> <body> <input type="file" id="myFile" autofocus> <p id="demo"></p> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*w w w .jav a2 s .c om*/ var x = document.getElementById("myFile").autofocus; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The autofocus
property sets or gets whether a file upload button should automatically get focus on page load.
This property mirrors the HTML autofocus attribute.
The autofocus
property accepts and returns a boolean type value.
Property Values
Value | Description |
---|---|
true | The file upload button gets focus |
false | Default. The file upload button does not get focus |
The autofocus
property returns true if the file upload button automatically gets focus when the page loads, otherwise it returns false.