Javascript examples for DOM HTML Element:Input Radio
The checked property sets or gets the checked state of a radio button.
This property reflects the HTML checked attribute.
Set the checked property with the following Values
Value | Description |
---|---|
true|false | Sets whether a radio button should be checked |
A Boolean, returns true if the radio button is checked, and false if the radio button is not checked
The following code shows how to Check and un-check a specific radio button:
<!DOCTYPE html> <html> <body> <form> What color do you prefer?<br> <input type="radio" name="colors" id="red">Red<br> <input type="radio" name="colors" id="blue">Blue </form>//from w ww.j a va 2s .c o m <button onclick="check()">Check "Red"</button> <button onclick="uncheck()">Uncheck "Red"</button> <script> function check() { document.getElementById("red").checked = true; } function uncheck() { document.getElementById("red").checked = false; } </script> </body> </html>