Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > when use ID and when use NAME in a HTML tag ??

Reply
Thread Tools

when use ID and when use NAME in a HTML tag ??

 
 
Ton den Hartog
Guest
Posts: n/a
 
      11-30-2003
I am confused, when use ID and when use NAME to identify an element in HTML
?

Ton den Hartog



--
Computer museum tonh: http://www.tonh.net - 10.000 visitors !!
GGGallery website generator: http://www.tonh.net/gggallery
Vrij Kunst Centrum : http://www.meesterschap.nu



 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-30-2003


Ton den Hartog wrote:

> I am confused, when use ID and when use NAME to identify an element in HTML
> ?


Well, check the HTML 4 specification
http://www.w3.org/TR/html4/
and if you have further questions ask in a newsgroup about HTML.
The id attribute is defined on (nearly) all elements and needs to be
unique in the whole document while the name attribute is defined for
elements like <input>, <textarea>, <select> where on form submission the
name of the element is paired with its value and sent to the server.
The name attribute is also defined on some elements like <img>, <form>,
<applet> back from pre HTML 4 times and still has some usefulness if you
want to script such elements in older browsers like Netscape 4.
--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      11-30-2003
"Ton den Hartog" <(E-Mail Removed)> writes:

> I am confused, when use ID and when use NAME to identify an element in HTML
> ?


According to the HTML 4 specification, "id" is recommended for most
elements where "name" is allowed.

Only on form controls ("input", "select", "button", "textarea", and
possibly "object") and the "param" and "meta" elements are "name"
important. On form controls elements, the "name" attribute value
specifies the "control name". In a "param" element it gives tha name
of the parameter. In a "meta" tag, it gives the "metainformation name",
whatever that is. If you have both "name" and "id" on such elements,
the "id" gives the globally unique identifier for the element, while
the "name" has a different meaning.

On all other elements that allow a name attribute ("a", "applet",
"form", "frame", "iframe", "img", and "map"), use "id". If you have
both "id" and "name" attributes on such an element, their values must
be equal. <URL:http://www.w3.org/TR/html4/struct/links.html#h-12.2.3>

/L
--
Lasse Reichstein Nielsen - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
Douglas Crockford
Guest
Posts: n/a
 
      11-30-2003
> I am confused, when use ID and when use NAME to identify an element in HTML
> ?


name is used to annotate POST data in forms. id is used to identify elements for
scripting and styling. Some browsers used them interchangeably, which is
confusing.

http://www.crockford.com

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      11-30-2003
JRS: In article <3fc9fddf$0$1489$(E-Mail Removed)4all.nl>, seen in
news:comp.lang.javascript, Ton den Hartog <ton.den.hartog.removespam@ton
h.net> posted at Sun, 30 Nov 2003 15:25:31 :-

>I am confused, when use ID and when use NAME to identify an element in HTML
>?


Since ID is required to be unique within the document, whilst NAME is or
can be limited in scope, then use NAME in preference to ID when you have
the choice.

Until recently, the page on which I am currently working used a
different NAME for every element, and every element was created by a
separate piece of HTML, which was satisfactory.

Now that more of the contents are computed rather than typed in, and the
page source is 20% smaller, it is convenient to use identical NAMEs for
matching items in Form A & Form B; the form NAME distinguishes between
them as necessary.

However, ID has one advantage : an editor can easily check that an ID is
unique within a straightforward page, and an ID can be located, easily
but not efficiently, by a search over all IDs.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
 
Reply With Quote
 
Frank Carr
Guest
Posts: n/a
 
      11-30-2003
"Douglas Crockford" <(E-Mail Removed)> wrote in message
news:b9da8$3fca2040$44a4afc0$(E-Mail Removed) ervers.com...

> Some browsers used them interchangeably, which is
> confusing.


I got bit by this one myself today. See my thread "Image Load in IE vs.
Mozilla".

Is there a good web site that compares these kinds of browser differences?
I'm in the process of moving from doing a lot of backend and database
development in VB/ASP/SQL to doing some front end Javascript programming so
anything along this line would be helpful.

--
Frank Carr
(E-Mail Removed)
http://www15.brinkster.com/vbnotebook


 
Reply With Quote
 
F. Da Costa
Guest
Posts: n/a
 
      12-01-2003
A while ago I printed (yep it still exists) a piece (and its still on my
desk) called:
Incompatibilities in IE and Netscape: HTML & Javascript.

Not sure whether its usefull.
Link: http://4guysfromrolla.com/webtech/011200-1.shtml

Cheers
Fermin DCG

Frank Carr wrote:
> "Douglas Crockford" <(E-Mail Removed)> wrote in message
> news:b9da8$3fca2040$44a4afc0$(E-Mail Removed) ervers.com...
>
>
>>Some browsers used them interchangeably, which is
>>confusing.

>
>
> I got bit by this one myself today. See my thread "Image Load in IE vs.
> Mozilla".
>
> Is there a good web site that compares these kinds of browser differences?
> I'm in the process of moving from doing a lot of backend and database
> development in VB/ASP/SQL to doing some front end Javascript programming so
> anything along this line would be helpful.
>


 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      12-01-2003
"F. Da Costa" <(E-Mail Removed)> writes:

> Incompatibilities in IE and Netscape: HTML & Javascript.
>
> Not sure whether its usefull.
> Link: http://4guysfromrolla.com/webtech/011200-1.shtml


It's comparing IE 4 to Netscape 4. I would say it's long past it's
expiration date.

(Please don't top post)
/L
--
Lasse Reichstein Nielsen - (E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
F. Kolb
Guest
Posts: n/a
 
      12-02-2003
"Ton den Hartog" <(E-Mail Removed)> wrote in message news:<3fc9fddf$0$1489$(E-Mail Removed)4all.nl>...
> I am confused, when use ID and when use NAME to identify an element in HTML
> ?
>
> Ton den Hartog


It really is simply as that:

WHEN using the DOM-Model... and you want to access several elements
with the same NAME (checkboxes / radio-buttons for example)
you HAVE TO use the name-attribute because there only exists the
"document.getElementsByName" function which IS handled STRICT in
NS/Mozilla-based browsers and "loosely" (id-attribute works too) by IE
browsers.

my personal opinion about this is:
W3C caused this confusion by entering a "getElementById" to retrieve
info from a UNIQUE element and to retriev info from MORE elements
sharing the same NAME a "getElemntsByName" !!! ...really NOT that
"Standard"-like.

so long...
 
Reply With Quote
 
GIMME
Guest
Posts: n/a
 
      12-02-2003
ID is used in DHTML to hide and place globs of html.

name is part of a name-value pair that gets submitted to a server
when there is a submit.


"Ton den Hartog" <(E-Mail Removed)> wrote in message news:<3fc9fddf$0$1489$(E-Mail Removed)4all.nl>...
> I am confused, when use ID and when use NAME to identify an element in HTML
> ?
>
> Ton den Hartog

 
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
How to find <tag> to </tag> HTML strings and 'save' them? mark@agtechnical.co.uk Python 7 03-26-2007 04:11 PM
HTML.Tag.BASE same as HTML.Tag.A carlbernardi@gmail.com Java 1 11-29-2006 03:41 AM
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
How Can I put XSL tag inside HTML form tag? RC Java 2 05-10-2005 06:26 PM
How Can I put XSL tag inside HTML form tag? RC XML 2 05-10-2005 05:55 PM



Advertisments