Input Radio checked Property
Example
Check and un-check a specific radio button:
function check() {
document.getElementById("red").checked = true;
}
function uncheck() {
document.getElementById("red").checked = false;
}
Try it Yourself »
Description
The checked property sets or returns the checked state of a radio button.
This property reflects the HTML checked attribute.
Browser Support
Property | |||||
---|---|---|---|---|---|
checked | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the checked property:
radioObject.checked
Set the checked property:
radioObject.checked = true|false
Property Values
Value | Description |
---|---|
true|false |
Specifies whether a radio button should be checked or not.
|
Technical Details
Return Value: | A Boolean, returns true if the radio button is checked, and false if the radio button is not checked |
---|
More Examples
Example
Find out if a radio button is checked or not:
var x = document.getElementById("myRadio").checked;
Try it Yourself »
Example
Use a radio button to convert text in an input field to uppercase:
document.getElementById("fname").value = document.getElementById("fname").value.toUpperCase();
Try it Yourself »
Example
Several radio buttons in a form:
var coffee = document.forms[0];
var txt = "";
var i;
for (i = 0; i < coffee.length; i++) {
if (coffee[i].checked) {
txt = txt + coffee[i].value + " ";
}
}
document.getElementById("order").value = "You ordered a coffee with: " + txt;
Try it Yourself »
Related Pages
HTML reference: HTML <input> checked attribute
❮ Input Radio Object