Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > label tag on radio buttons

Reply
Thread Tools

label tag on radio buttons

 
 
Shailesh Humbad
Guest
Posts: n/a
 
      05-13-2004
I can use a label tag on radio buttons like this:

<input type="radio" name="animal" id="animal1">
<label for="animal1">Giraffe</label>
<input type="radio" name="animal" id="animal2">
<label for="animal2">Antelope</label>

My question is, are there any browser compatibility issues with using
a different name and id in the same form element? Will all the
browsers that support this feature submit the form correctly using the
"name" attribute as the real name of the submitted radio field.
 
Reply With Quote
 
 
 
 
Toby A Inkster
Guest
Posts: n/a
 
      05-13-2004
Shailesh Humbad wrote:

> I can use a label tag on radio buttons like this:
>
> <input type="radio" name="animal" id="animal1">
> <label for="animal1">Giraffe</label>
> <input type="radio" name="animal" id="animal2">
> <label for="animal2">Antelope</label>
>
> My question is, are there any browser compatibility issues with using
> a different name and id in the same form element?


No browser compatibility problems. Indeed in this situation, you *MUST*
use a different name and ID.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - http://www.goddamn.co.uk/tobyink/?page=132

 
Reply With Quote
 
 
 
 
Foofy (formerly known as Spaghetti)
Guest
Posts: n/a
 
      05-14-2004
On Thu, 13 May 2004 19:19:36 +0100, Toby A Inkster <>
wrote:

> No browser compatibility problems. Indeed in this situation, you *MUST*
> use a different name and ID.


Something I've always wondered is why it uses the ID attribute, especially
since that must be unique throughout the document? What about a page with
multiple forms that are similar? What's the reason behind this? I'm just
curious...


--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
 
Reply With Quote
 
Toby A Inkster
Guest
Posts: n/a
 
      05-14-2004
Foofy (formerly known as Spaghetti) wrote:

> Something I've always wondered is why it uses the ID attribute, especially
> since that must be unique throughout the document? What about a page with
> multiple forms that are similar? What's the reason behind this? I'm just
> curious...


I'm not sure what you don't get.

In the case of radio buttons, each one needs the same name -- it's how
they're grouped.

IDs are always unique and they need to be for the purpose of linking to
fragment identifiers, document.getElementById, etc.

So, if one is assigning IDs to a group of radio buttons then they must all
be different.

A technique I often use is to give radio buttons an ID of name_value. That
is:

<input type="radio" name="food" value="beef" id="food_beef">
<label for="food_beef">I want the beef meal</label>
<input type="radio" name="food" value="fish" id="food_fish">
<label for="food_fish">I want the fish meal</label>
<input type="radio" name="food" value="veg" id="food_veg">
<label for="food_veg">I want the vegitarian meal</label>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - http://www.goddamn.co.uk/tobyink/?page=132

 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      05-14-2004
"Foofy (formerly known as Spaghetti)" <> wrote in message news:<>...

> Something I've always wondered is why it uses the ID attribute, especially
> since that must be unique throughout the document?


Fundamentally I think this is a legacy question. The "id" attribute
has type of "ID" (NB - there's nothing magic about the name, it only
gains this behaviour because the type is set in the DTD). "ID" type is
already well-established from SGML as having document-wide scope for
its uniqueness. Although HTML _could_ have been formulated to permit
id attributes that were unique in just the form, that would have been
a variation from existing practice for no real benefit.

There's also the issue that id is there as much to support the DOM
(obviously a document-wide scope) as it is to support form elements.


I'm an old desktop app coder, from the days before the web. My
practice is to give form elements atributes like this:
<input name="Username" id="txtUsername" ... >

If I'm doing multi-form work on the same page, then I concatenate the
form id:
<form id="frmLogon" ... >
<input name="Username" id="txtLogon_Username" ... >
 
Reply With Quote
 
Mitja
Guest
Posts: n/a
 
      05-14-2004
Shailesh Humbad <>
(newsEOoc.7808$) wrote:
> I can use a label tag on radio buttons like this:
>
> <input type="radio" name="animal" id="animal1">
> <label for="animal1">Giraffe</label>
> <input type="radio" name="animal" id="animal2">
> <label for="animal2">Antelope</label>
>
> My question is, are there any browser compatibility issues with using
> a different name and id in the same form element? Will all the
> browsers that support this feature submit the form correctly using the
> "name" attribute as the real name of the submitted radio field.


No need to worry. Still, you can alternatively use
<label><input type="radio" name="foo">bar</input></label>
to avoid the IDs altogether


 
Reply With Quote
 
Neal
Guest
Posts: n/a
 
      05-14-2004
On Thu, 13 May 2004 20:54:03 -0400, Foofy (formerly known as Spaghetti)
<> wrote:

> On Thu, 13 May 2004 19:19:36 +0100, Toby A Inkster
> <> wrote:
>
>> No browser compatibility problems. Indeed in this situation, you *MUST*
>> use a different name and ID.

>
> Something I've always wondered is why it uses the ID attribute,
> especially since that must be unique throughout the document? What
> about a page with multiple forms that are similar? What's the reason
> behind this? I'm just curious...
>
>



ID's are indeed one-to-a-page. And that's why it works with label. Each
label matches one and only one form element. Of what use would a label
affecting two or more checkboxes be?

If you have two similar forms, all the more reason to ensure your labels
are unique in each.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Created Radio Buttons displaying as if they were conventional buttons Dr. Leff Javascript 3 10-15-2007 09:47 PM
Created Radio Buttons displaying as if they were conventional buttons Dr. Leff Javascript 3 10-15-2007 05:18 AM
ASP.NET Reset Radio Button in a group of Radio Buttons Scott D Johnson ASP .Net 1 09-27-2006 10:38 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
label versus asp:label Question. Thanks. Shapper ASP .Net 2 05-07-2005 05:55 AM



Advertisments