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