defaultChecked
Value: Boolean. Read-Only
Compatibility: WinIE3+, MacIE3+, NN2+, Moz+, Safari+
Sometimes you may find it beneficial to know if the initial setting of a checkbox has changed. The checked property alone can't tell you this because it reflects only the current state of a checkbox. Another property, defaultChecked, keeps up with the initial state of a checkbox.
If you add the checked attribute to the <input> definition for a checkbox, the defaultChecked property for that object is true; otherwise, the property is false. Having access to this property enables your scripts to examine checkboxes to see if they have been adjusted (presumably by the user, if your script does not set properties).
The following function is designed to compare the current setting of a checkbox against its default value:
function compareBrowser(thisBox) {
if (thisBox.checked != thisBox.defaultChecked) {
// statements about using a different set of HTML pages
The if construction compares the current status of the box against its default status. Both are Boolean values, so they can be compared against each other. If the current and default settings don't match, the function goes on to handle the case in which the current setting is other than the default.
Related Items: checked, value properties.
Post a comment