You are here: Reference > JavaScript > client-side > HTML DOM > properties > defaultChecked (input)

defaultChecked property (input)

Browser support:
Specifies or returns the initial state of a input:checkbox or input:radio elements. The initial state can be set with the CHECKED attribute in HTML.
If you want to get or set the current state of the object, use the checked property.
The defaultChecked property can be useful if you want to detect whether the checked state of a control has been changed.


You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

Boolean that indicates the state of the object.
One of the following values:
By default the input:checkbox or input:radio is not checked.
By default the input:checkbox or input:radio is checked.
Default: true.

Example HTML code 1:

This example illustrates the use of the defaultChecked property:
    <script type="text/javascript">
        function DetectCheckedChanges () {
            var myCheckBox = document.getElementById ("myCheckBox");
            var defChecked = myCheckBox.defaultChecked;
            var currChecked = myCheckBox.checked;
            if (defChecked == currChecked) {
                alert ("The checked state of the control has not changed!");
            else {
                alert ("The checked state of the control has changed!");
    <input type="checkbox" id="myCheckBox" checked="checked" />Do you like chocolate?
    <br /><br />
    <button onclick="DetectCheckedChanges ();">
        Detect whether the default state of the checkbox has changed!
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content