Input Radio defaultChecked Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Radio

Description

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

Return Value

TypeDescription
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:

Demo Code

ResultView the demo in separate window


<!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>

Related Tutorials