Javascript Reference - HTML DOM Input Radio autofocus Property








The autofocus property sets or gets whether a radio button can auto focus when the page loads.

Browser Support

autofocus Yes Yes Yes Yes Yes

Syntax

Return the autofocus property.

var v = radioObject.autofocus 

Set the autofocus property.

radioObject.autofocus=true|false

Property Values

Value Description
true|false Set whether a radio button can auto focus when the page loads
  • true - The radio button gets focus
  • false - Default. The radio button does not get focus




Return Value

A Boolean type value, true if the radio button can auto focus when the page loads, otherwise false.

Example

The following code shows how to check if a radio button can auto focus upon page load.


<!DOCTYPE html>
<html>
<body>
<!--   w  w  w  . j a v a2  s  . c om-->
Radio Button: <input type="radio" id="myRadio" autofocus>
<button onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myRadio").autofocus;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: