Input Radio checked Attribute
Definition and Usage
checked
Sets or returns the selected state of a radio button.
This attribute reflects the HTML checked attribute.
See also:
HTML Reference Manual:HTML <input> checked Attribute
Example
Example 1
Select or deselect a specified radio button:
function check() { document.getElementById("red").checked = true; } function uncheck() { document.getElementById("red").checked = false; }
Example 2
Check if a radio button is selected:
var x = document.getElementById("myRadio").checked;
Example 3
Use radio buttons to convert text in an input field to uppercase:
document.getElementById("fname").value = document.getElementById("fname").value.toUpperCase();
Example 4
Several radio buttons in the 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 coffee with: " + txt;
Syntax
Return the checked attribute:
radioObject.checked
Set the checked attribute:
radioObject.checked = true|false
Attribute Value
Value | Description |
---|---|
true|false |
Specifies whether the radio button should be selected.
|
Technical Details
Return Value: | Boolean value, returned if the radio button is selected true ; otherwise return false . |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |