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

T

Ton den Hartog

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

Ton den Hartog
 
M

Martin Honnen

Ton said:
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.
 
L

Lasse Reichstein Nielsen

Ton den Hartog said:
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
 
D

Douglas Crockford

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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
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.
 
F

Frank Carr

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.
 
F

F. Kolb

Ton den Hartog said:
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...
 
G

GIMME

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top