[thelist] FireFox doesn't do backgroundColor forcheckboxesorradios?

Dave Merrill dmerrill at usa.net
Wed Feb 9 09:19:59 CST 2005

Thanks Keith, right on the money.

Using <label> does mean using IDs on everything. Gives you more flexibility
for other manipulation anyway. Do you just use the field name as the id,
except when it's a multiple (radios, checkboxes)?

For multiples, do you make the overall field label for the group the
official label, or the text associated with each individual radio? If its
the overall field label, do you associate the official label just with the
first one of the series? For IDs on those, do you just not use one for the
rest of the series? Append an index number?

I've also been looking at table-less form layout
(http://www.quirksmode.org/css/forms.html). Going that way would allow the
label to contain the control, so no id would be needed. My understanding
though is that that wouldn't work for multiples, since only one control can
be inside a label.

Re performance, I recently worked on a large joint surgery outcome research
project, where some of the forms were nasty big, even split into multiple
pages. JS seems pretty fast, and performed fine in those contexts, but I
wasn't doing multiple runs of this kind of scan, which you would have to do.

Thanks again,

Dave Merrill

Keith Gaughan wrote:
> <tip title="How to find the label associated with a form element">
> I always use the <label> tag in my client-side validation. It's the best
> way to go anyway. Here's how I look for the label associated with the:
> function GetLabelForId(id)
> {
>      var labels = document.getElementsByTagName('label');
>      for (var i = 0; i < labels.length; i++)
>      if (labels[i].htmlFor == id)
>          return labels[i];
>      return null;
> }
> This takes the id of the invalid field and searches for the label field
> associated with it though the "for" attribute.
> This is a better visual indication of which fields are dodgy. Also, it
> doesn't clash with thing like the auto-fill in the Google toolbar.
> I use a class called "bad" to indicate which ones didn't validate. When
> it's going through each one of the form field, I clear this from the
> list of classes assigned to the label. Then I validate the associated
> field, and if it's invalid, append the class again.
> You could speed this up by doing a search for all the labels associated
> with all the fields to validate. My current validation library does a
> scan for each as needed, which on particularly large forms could be
> slow, (approximately n^2 scans: not nice), but the number of fields is
> usually small enough for this not to make much of a difference.
> </tip>
> K.

More information about the thelist mailing list