Javascript examples for DOM HTML Element:Input Email field
The autofocus property sets or gets whether an email field should get focus when the page loads, or not.
This property reflects the HTML autofocus attribute.
Set the autofocus property with the following Values
Value | Description |
---|---|
true|false | Sets whether an email field should get focus when the page loads |
A Boolean, returns true if the email field gets focus when the page loads, otherwise it returns false
The following code shows how to check if an email field automatically gets focus upon page load:
<!DOCTYPE html> <html> <body> E-mail: <input type="email" id="myEmail" autofocus> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* ww w . jav a 2s .c om*/ var x = document.getElementById("myEmail").autofocus; document.getElementById("demo").innerHTML = x; } </script> </body> </html>