473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
9 6993


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
"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
> 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
"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
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
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
"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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Halldór Ísak Gylfason | last post by:
In my application I have an iframe that is empty (and not visible) initially, however when a user presses a button a form is programmatically submitted and the target is set to the IFrame. I...
3
by: Stevie_mac | last post by:
It might be me but... I dont seem to get a Page_Load event when a opening an ASPX in an iFrame. I do geta Page_Load event when an item on the ASPX (inside the iFrame) is clicked but then...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
1
by: rbinington | last post by:
Hi, I am trying to write a DNN module that has the ability to insert articles into an article repository. I want the users to be able to move pages around and enter text into the FCKEditor. I...
9
by: GloStix | last post by:
Okay, when I click the link it dissapears and makes a white space underneath it but the space is clickable. so when you click the space, the link actually works Used Firefox 3.0 RC2 for this. OS X...
1
by: robin1983 | last post by:
Dear All, I got stuck in simple problem, I have a two php file one for registration form and one for to check and insert into the table. The problem is that when I get any kind error in...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.