J
Jeremy
Given a group of radio buttons with the same "name" property, all with
onchange handlers set -- what should happen when the user selects a
different radio button than the one currently selected (assuming one is
currently selected)?
It seems to me that two radio buttons are changing - one is changing
from checked to unchecked, and the other changing from unchecked to
checked (since radio buttons with the same "name" attribute are
considered mutually exclusive). However, it seems to be the case that
only one change event is fired -- for the newly selected radio button.
The one that is no longer checked is not notified of such.
Technically, the W3 spec doesn't really deal with this case. It says:
The onchange event occurs when a control loses the input focus
and its value has been modified since gaining focus.[1]
In this case, technically at least, the *value* of the radio button is
not being changed - only whether or not it is checked (this is distinct
from value). If they are following this definition, though, then
*neither* event should be fired. Additionally, the event is fired (in
all but IE) when the button *gains* focus, not *loses* focus, which is
the opposite of the specified behavior.
All user agents that I tested (Moz, IE, Opera, Safari) seem to act in
roughly the same way. But I can't imagine why.
Any thoughts?
Test case:
http://duckwizard.com/clj/radio-onchange/
Reference:
[1] http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.3
Jeremy
onchange handlers set -- what should happen when the user selects a
different radio button than the one currently selected (assuming one is
currently selected)?
It seems to me that two radio buttons are changing - one is changing
from checked to unchecked, and the other changing from unchecked to
checked (since radio buttons with the same "name" attribute are
considered mutually exclusive). However, it seems to be the case that
only one change event is fired -- for the newly selected radio button.
The one that is no longer checked is not notified of such.
Technically, the W3 spec doesn't really deal with this case. It says:
The onchange event occurs when a control loses the input focus
and its value has been modified since gaining focus.[1]
In this case, technically at least, the *value* of the radio button is
not being changed - only whether or not it is checked (this is distinct
from value). If they are following this definition, though, then
*neither* event should be fired. Additionally, the event is fired (in
all but IE) when the button *gains* focus, not *loses* focus, which is
the opposite of the specified behavior.
All user agents that I tested (Moz, IE, Opera, Safari) seem to act in
roughly the same way. But I can't imagine why.
Any thoughts?
Test case:
http://duckwizard.com/clj/radio-onchange/
Reference:
[1] http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.3
Jeremy