Richard said:
RobG wrote:
<snip>
You shouldn't let worrying about getting them wrong prevent you from
attempting to explain the finer details. Someone will correct them if
you do make errors, leaving the specifics much clearer (or maybe just
fresher) in your mind.
Thanks for the encouragement, my real motive was lack of time to
properly investigate. So here goes...
Further investigation reveals that IE does not fire the onchange event
until the checkbox loses focus. Clicking "yes" initially just sets
that checkbox to checked. If you then click in the page, the onchange
fires and the second "yes" is checked. But, if you click "no" instead,
the first "yes" onchange fires and changes the second "yes" to clicked
so you have an apparent reversal of logic.
In fact, all that's happened is that the second "no" onchange has not
yet fired. Clicking anywhere else fires it - so if you click back on
the first "yes", it becomes checked, the first "no" onchange fires and
the second "no" is checked. The onchange from the first "yes" is still
lurking....
Setting the initial state of the first "yes" to checked in the HTML can
create even more confusing results.
Mozilla fires the onchange as soon as the checkbox changes BUT on text
inputs, its onchange isn't fired until the input loses focus (if the
text has been modified).
But who is wrong? As luck would have it, MS seem to have gotten this
one right. The W3C HTML 4.01 spec says:
"The onchange event occurs when a control loses the input
focus and its value has been modified since gaining focus."
Mozilla's behaviour, whilst more logical, is actually wrong. And using
checkboxes to cause UI events to be fired is also "wrong", but it's not
at odds with any open standard that I'm aware of (not much solace there
I'm afraid!)
So in fact my presumption regarding references to form elements being
the cause was wrong (thanks Richard), however...
It is still better (IMHO) to refer to form elements the way indicated.
The bottom line is that the behaviour of "onchange" is not consistent
across browsers or (in the case of Mozilla) for different elements in
the same browser and therefore shouldn't be relied upon.
Further more, to achieve the desired result, onclick is more consistent
and should be used instead in this case.
Lastly, clicks on checkboxes should not be used to fire UI events
(bring up dialogs, popup windows, change content, etc.) but that is
just my opinion. Use buttons or other UI widgets that users *expect*
to cause UI changes - the "least surprise" principle.
However, there is considerable value in the act of attempting to explain
things to others. As Lasse Reichstein Nielsen once observed, you can be
certain that you understand something yourself when you can explain it
to others such that they then understand (assuming a reasonably
receptive and perceptive other).
[...]
Yes, hence why I lurk here at all.
