Javascript Reference - HTML DOM Input Radio defaultChecked Property








The defaultChecked property returns the default value of the checked attribute.

Browser Support

defaultChecked Yes Yes Yes Yes Yes

Syntax

var v = radioObject.defaultChecked 

Return Value

A Boolean type value, true if the radio button is checked by default, otherwise false.





Example

The following code shows how to check if a radio button is checked by default.


<!DOCTYPE html>
<html>
<body>
<!--   ww w. j  ava2 s. co  m-->
Radio button: <input type="radio" name="colors" id="myRadio" checked>
<button onclick="myFunction()">test</button>
<p id="demo"></p>

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

The code above is rendered as follows: