X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Input Radio checked Property

Input Radio Object Reference Input Radio Object

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 »


Definition and Usage

The checked property sets or returns the checked state of a radio button.

This property reflects the HTML checked attribute.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The checked property is supported in all major browsers.


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

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;

The result of x will be:

true

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].coffee;
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 Reference Input Radio Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook