[whatwg] LABEL and radio/checkbox onclick

Matthew Raymond mattraymond at earthlink.net
Sun Jul 18 08:17:54 PDT 2004


Matthew Thomas wrote:
> On 19 Jul, 2004, at 12:06 AM, Hallvord Reiar Michaelsen Steen wrote:
>> It is AFAIK not covered by any spec whether clicking a LABEL should
>> trigger an onClick event on the associated control. Implementations
>> have been inconsistent. IMO the most useful implementation is that
>> clicking a label should trigger onClick for form controls - at least
>> for those that change state (such as a checkbox).
> 
> In non-Web GUIs, labels are only clickable for checkboxes and 
> radiobuttons.* It would be nice if exactly the same was true for 
> HTML+WF2, otherwise people would end up wasting time clicking listbox 
> etc labels in native apps and wondering why nothing was happening.
> 
> * And disclosure triangles, but they're not in HTML or WF2.

    The W3C HTML 4.01 specification makes it pretty clear that a label 
passes focus to the control with which it is associated. As a result, I 
think it should always be the case that clicking the label gives the 
associated control focus. If web authors don't want this to be the case, 
they should just use text instead of <label>.

    What the specification doesn't seem to state is whether the label 
should pass on a click to its associated control, thus causing an 
onclick event for the control. Clearly, since clicking on the label of a 
radio button or checkbox in a standard GUI would cause a click of the 
associated control, this behavior should also occur in HTML for those 
control types. It is more difficult to say whether it could occur for 
other types of controls.

    Because there is a workaround (using just text instead of <label>), 
I would suggest that we define the standard behavior of clicking on a 
label as being the same as clicking on the control. I can think of no 
situation off-hand where this would cause a problem for the user when 
implemented in a user agent. The worst case scenario is that the user 
would try to click on a label in a non-Web UI, notice that nothing 
happened, and click on the control itself. Besides, it's the default 
behavior for all labels with explicitly associated controls on all major 
browsers.

    The only loose end I see is that for <label> elements with 
implicitly associated controls, clicking on the label in Internet 
Explorer does nothing. (This includes radio buttons and checkboxes.) 
This is actually a violation of the specification (not to mention an 
outright bug for checkboxes and radio buttons), but perhaps it would be 
addressed in IE7 and the upcoming WF2 emulation layer.



More information about the whatwg mailing list