Here's my HTML:
<input id="test" type="checkbox" checked="">
Here's a Firebug excerpt:
>>> test
<input id="test" type="checkbox" checked="">
>>> test.checked = false
false
>>> test
<input id="test" type="checkbox" checked="">
Um...am I missing something, or should that last line not read the following?
<input id="test" type="checkbox">
UI-wise, the checkbox does indeed uncheck when I execute the checked = false line.
Anyway, if there's some legitimate explanation for this, then what's the proper way to uncheck a checkbox from JavaScript, if not checked = false?
The
valueattribute ofinput type="text"and thecheckedorselectedattributes ofinput type="checkbox",radioandoptioncorrespond to the initial value of the form field, not the current value the user or script has set. Consequently changing thecheckedproperty does not alter the attribute value, and setting thecheckedattribute does not alter the real visible value that's going to be submitted with the form.The
checked="checked"attribute corresponds to thedefaultCheckedDOM property, not thecheckedproperty. Similarly, thevalue="..."attribute corresponds todefaultValue.(Note there are IE gotchas here due to IE not knowing the difference between a property and an attribute.)