Input Checkbox checked Attribute
Definition and Usage
checked
Sets or returns the checked state of the checkbox.
This property reflects the HTML checked attribute.
See also:
HTML Reference Manual:HTML <input> checked Attribute
Example
Example 1
Set the checked state of the checkbox:
function check() { document.getElementById("myCheck").checked = true; } function uncheck() { document.getElementById("myCheck").checked = false; }
Example 2
Check if the checkbox is selected:
var x = document.getElementById("myCheck").checked;
Example 3
Use checkboxes to convert text in input fields to uppercase:
document.getElementById("fname").value = document.getElementById("fname").value.toUpperCase();
Example 4
Several checkboxes 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:
checkboxObject.checked
Set the checked attribute:
checkboxObject.checked = true|false
Attribute Value
Value | Description |
---|---|
true|false |
Specifies whether the checkbox should be selected
|
Technical Details
Return Value: | Boolean value, returned if the checkbox is selected true If the checkbox is not selected, it returns false . |
---|
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |