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;
}

Try it yourself

Example 2

Check if a radio button is selected:

var x = document.getElementById("myRadio").checked;

Try it yourself

Example 3

Use radio buttons to convert text in an input field to uppercase:

document.getElementById("fname").value = document.getElementById("fname").value.toUpperCase();

Try it yourself

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;

Try it yourself

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.

  • true - The radio button is selected
  • false - Default. The radio button is not 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