Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
HTML DOM Input Radio autofocus property
The HTML DOM input radio autofocus property is associated with the HTML element’s autofocus attribute. This property is used for setting or returning whether the input radio button automatically be focused when the page loads or not.
Syntax
Following is the syntax for −
Setting the autofocus property.
radioObject.autofocus = true|false
Here, true represents the radio button should get focus and false represents otherwise. It is set to false by default.
Example
Let us look at an example for the Input Radio autofocus property −
Input password autofocus property
Output
This will produce the following output −

On clicking the CHECK FOCUS button −

In the above example −
We have created an input field with type=“radio”, id=“rad1”, name=“BTN” and it has the autofocus property enabled i.e set to true −
Password:
We have then created a button CHECK FOCUS that will execute the FocusVal() method when clicked by the user −
The FocusVal() method gets the input element with type radio using the getElementById() method and gets it autofocus property. The autofocus property returns true and false depending on the radio button autofocus attribute value. This value is assigned to variable R and displayed in the paragraph with id “Sample” using its innerHTML property.
function FocusVal() {
var R = document.getElementById("rad1").autofocus;
document.getElementById("Sample").innerHTML = "The radio button has autofocus property set to "+R;
} 