You are here: Reference > JavaScript > client-side > HTML DOM > properties > checked (input(checkbox, radio))

checked property (input(checkbox, radio))

Browser support:
Sets or retrieves the state of a check box or a radio button.
The CHECKED attribute in HTML and the checked property in JavaScript work differently for these controls. You can set the initial state with the CHECKED attribute, while the checked property contains the actual state of the control. If you want to get or set the initial state in JavaScript, use the defaultChecked property.

Syntax:

object.checked;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: CHECKED

Possible values:

Boolean that indicates the checked state of the object.
One of the following values:
false
The element is not checked or it is in an indeterminable state.
true
The element is checked.
Default: false.

Example HTML code 1:

This example illustrates the use of the CHECKED attribute:
<input type="checkBox" /> Initially not checked <br />
<input type="checkBox" checked="checked" /> Initially checked
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the checked property:
<head>
    <script type="text/javascript">
        function GetCheckedState () {
            var input = document.getElementById ("myInput");
            var isChecked = input.checked;
            isChecked = (isChecked)? "checked" : "not checked";
            alert ("The checkBox is " + isChecked);
        }
    </script>
</head>
<body>
    Check it!
    <input type="checkBox" id="myInput" onclick="GetCheckedState ();"/>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content