[thelist] checkbox referencing

James Aylard evolt at pixelwright.com
Tue May 28 17:49:04 CDT 2002


Tom,

> I am mimicking link behavior by <span>ing the text labels for the radio
buttons with a hand
> cursor. Of course, clicking this doesn't change the radio button (only
changes the frames). So I
> needed to include switching the radio button if they clicked the fake
"link" instead of the
> button.

    A suggestion: drop the javascript approach altogether, and wrap your
spanned "link" text within a <label> element. The label element uses a "for"
attribute that references the id of the particular form element for which it
is a label, ergo:

<input id="cb1"
  name="cb"
  type="checkbox"><label for="cb1">Click Me!</label>

    That way, you take advantage of behavior built into HTML (and
implemented, fortunately, by IE 4+) whereby clicking on the label
automatically activates the element which it labels. All of which brings up
a second issue: _never_ use the same id for multiple elements. It is illegal
html, and creates scripting headaches of the kind that you are seeing (btw,
doing so creates a collection for that id in IE; other browsers will likely
balk at the approach, however).

James Aylard




More information about the thelist mailing list