The autofocus
property sets or gets
if a password field can auto focus when the page loads.
autofocus |
Yes | Yes | Yes | Yes | Yes |
Return the autofocus property.
var v = passwordObject.autofocus
Set the autofocus property.
passwordObject.autofocus=true|false
Value | Description |
---|---|
true|false | Set if a password field can auto focus when the page loads
|
A Boolean type value, true if the password field can automatically get focus when the page loads, otherwise false.
The following code shows how to check if a password field can auto focus upon page load.
<!DOCTYPE html>
<html>
<body>
<!--from w w w . j av a 2 s. co m-->
Password: <input type="password" id="myPsw" autofocus>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myPsw").autofocus;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: