[Javascript] javascript and id's

Anthony Ettinger apwebdesign at yahoo.com
Tue Oct 4 13:18:20 CDT 2005



--- Paul Novitski <paul at novitskisoftware.com> wrote:

> At 10:22 AM 10/4/2005, Anthony Ettinger wrote:
> >Well, from what I've talked with some co-workers,
> they
> >are saying 'id' should be used instead of 'name'.
> >Although I'm sure they will always be backwards
> >compatible. The problem I raised was what do you do
> in
> >a radio group? where id would/should be the name
> (but
> >id implies only one per page).
> >
> >I don't know who is right/wrong. But the latest
> >javascript I've seen all seems to revolve around
> >getElementById.
> 
> 
> The NAME attribute isn't unique -- there can be more
> than one element 
> with the same name on the page.  This is exactly how
> radio buttons 
> work -- they all share the same name, and only the
> selected element's 
> value is transmitted on submit.  If more than one
> active field has 
> the same name in a form, their values are submitted
> as a comma-delimited list.
> 
> As I understand it, the NAME attribute today is used
> to organize form 
> fields for submission but isn't otherwise useful in
> the DOM.
> 
> In the DOM, the two methods we're given to locate
> items immediately 
> are getElementById() and getElementsByTagName(), but
> 
> "getElementsByName()" doesn't exist.
> 
> See the HTML 4.01 spec:
>
http://www.w3.org/TR/html4/interact/forms.html#adef-name-FORM
> "name = cdata [CI]
>      "This attribute names the element so that it
> may be referred to 
> from style sheets or scripts. Note. This attribute
> has been included 
> for backwards compatibility. Applications should use
> the id attribute 
> to identify elements."
> 
> It's always a good idea to run your HTML through the
> W3C validator 
> http://validator.w3.org/ -- it will point out if &
> where your markup 
> strays from the recommended path.

I haven't tested it, but if you leave name attribute
off, the id gets sent as the parameter name. The only
case I see this being a problem is when you have
objects with the same name (ie- a radio list).

So I'm guessing 'name' will not be deprecated in the
future.



Anthony Ettinger
ph: (408) 656-2473
blog: http://www.chovy.com


		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com



More information about the Javascript mailing list