Check if a radio button is checked by default:
var x = document.getElementById("myRadio").checked;
Click the button to find out if the radio button is checked by default.
<!DOCTYPE html> <html> <body> Radio button: <input type="radio" name="colors" id="myRadio" checked> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// www . jav a 2 s . c om var x = document.getElementById("myRadio").checked; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The defaultChecked property returns the default value of the checked attribute.
This property returns true if the radio button is checked by default, otherwise it returns false.