Radio Ga Ga
I’m working on a form. It’s an old form and I’m trying to drag it, kicking and screaming, from the past into the semantic HTML world.
But I’ve come across something that’s bugging me. It’s all about Radio Buttons.
Here’s a little sample…

I’ve got a fieldset with a legend defining part of the form. The label for each form element is on the left, and I’m using the <label for=""> tag to associate the label with it’s form field. In the picture, the “job title” text is the label for the corresponding form field.
The code looks something like…
<fieldset> <legend>Duplication Request Details</legend> <div> *<label for=“jobTitle”>Job title</label>: <input name=“jobTitle” type=“text” id=“jobTitle”> </div> </fieldset>
I removed the table code for clarity. (Yes, there are tables involved, just to make things a bit more complicated)
But what happens when I get to the Packaging Type? The left hand column is no longer the label for the radio buttons. A label can only use it’s for attribute to associate itself with the id attribute of another element.
In Packaging Type, the label now conceptually applies to the entire button group. A button group, in HTML, is defined by the buttons name attribute, which we can’t bind a label to.
Therefore the following, which is what I *want* to do, is invalid code…
<div> *<label for=“packaging”>Packaging type</label>: <input type=“radio” value=“paper” name=“packaging”>Paper sleeve <input type=“radio” value=“plastic” name=“packaging”>Plastic sleeve </div>
(Note the attempt to associate a label with a name.)
So what are my alternatives?
A valid solution would be…
<div> *Packaging type: <input type=“radio” value=“paper” id=“paper” name=“packaging”><label for=“paper”>Paper sleeve</label> <input type=“radio” value=“plastic” id=“plastic” name=“packaging”><label for=“plastic”>Plastic sleeve</label> </div>
But that doesn’t associate the buttons with their purpose: identifying the packaging type, as defined by the text in the left hand column.
Here is where HTML is letting me down
It would be nice if we could have something like a ButtonGroup tag which could contain other buttons, but which could have it’s own id. Something like…
<div> *<label for=“packagingGroup”>Packaging type</label>: <buttongroup id=“packagingGroup”> <input type=“radio” value=“paper” id=“paper” name=“packaging”><label for=“paper”>Paper sleeve</label> <input type=“radio” value=“plastic” id=“plastic” name=“packaging”><label for=“plastic”>Plastic sleeve</label> </buttongroup> </div>
Mmmmm. That would be nice
We would preserve the single label-to-button relationship, but would also have a label-to-group relationship. All the id’s are unique, so we’re not breaking any rules there.
Perhaps I should go check out the HTML5 effort and make a few suggestions…
