By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,818 Members | 2,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,818 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jul 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a


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/

Jul 20 '05 #2

P: n/a
"Ton den Hartog" <to***********************@tonh.net> 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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

P: n/a
> 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

Jul 20 '05 #4

P: n/a
"Douglas Crockford" <no****@covad.net> wrote in message
news:b9***************************@msgid.meganewss 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
jf****@msn.com
http://www15.brinkster.com/vbnotebook
Jul 20 '05 #5

P: n/a
JRS: In article <3f**********************@news.xs4all.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.
Jul 20 '05 #6

P: n/a
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" <no****@covad.net> wrote in message
news:b9***************************@msgid.meganewss 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.


Jul 20 '05 #7

P: n/a
"F. Da Costa" <da*****@xs4all.nl> 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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #8

P: n/a
"Ton den Hartog" <to***********************@tonh.net> wrote in message news:<3f**********************@news.xs4all.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...
Jul 20 '05 #9

P: n/a
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" <to***********************@tonh.net> wrote in message news:<3f**********************@news.xs4all.nl>...
I am confused, when use ID and when use NAME to identify an element in HTML
?

Ton den Hartog

Jul 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.