Javascript examples for DOM HTML Element:Input Radio
The defaultChecked property returns the default value of the checked attribute.
Type | Description |
---|---|
Boolean | Returns true if the radio button is checked by default, otherwise it returns false. |
The following code shows how to Check if a 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() {//from w w w.j ava2s .c om var x = document.getElementById("myRadio").checked; document.getElementById("demo").innerHTML = x; } </script> </body> </html>