The defaultChecked
property returns the default value of the checked attribute.
defaultChecked |
Yes | Yes | Yes | Yes | Yes |
var v = radioObject.defaultChecked
A Boolean type value, true if the radio button is checked by default, otherwise false.
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: