defaultChecked property (input)
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.
The defaultChecked property can be useful if you want to detect whether the checked state of a control has been changed.
Syntax:
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:
|
||||
<head> <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!"); } } </script> </head> <body> <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! </button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
HTML elements:
Related pages:
External links:
User Contributed Comments