Find out if a password field automatically gets focus on page load:
var x = document.getElementById("myPassword").autofocus;
Click the button to find out if the password field automatically gets focus on page load.
<!DOCTYPE html> <html> <body> Password: <input type="password" id="myPsw" autofocus> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w .ja va2 s .com var x = document.getElementById("myPsw").autofocus; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The autofocus property sets or gets whether a password field should automatically get focus on page load.
This property mirrors the HTML autofocus attribute.
Value | Description |
---|---|
true | The password field gets focus |
false | Default. The password field does not get focus |
The autofocus property returns true if the password field automatically gets focus on page load, otherwise it returns false.