Input Text autofocus property
Example
Check whether the text field automatically gets focus after the page loads:
var x = document.getElementById("myPassword").autofocus;
x The returned result is:
true
Try it »
Definition and Usage
The autofocus property is used to set or return whether the text field automatically gets focus after the page loads.
This attribute reflects the HTML autofocus attribute.
Browser support





All major browsers support the autofocus attribute.
**Note:** Internet Explorer 9 and earlier IE versions, or Opera 12 and earlier versions of browsers, do not support the autofocus property.
Syntax
Return the autofocus property:
textObject
.autofocus
Set the autofocus property:
textObject
.autofocus=true|false
Attribute values
| Value | Description |
|---|---|
| true|false | Describes whether the text field gets focus after the page loads
|
Technical Details
| Return value: | Boolean, returns true if the text field automatically gets focus after the page loads, otherwise returns false. |
|---|
Related pages
HTML Reference Manual: HTML autofocus attribute
The Input Text object