473,322 Members | 1,398 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,322 software developers and data experts.

name vs id in getElementById in NS

Should I use both name and id
<div name="abc" id="abc"> for using getElementById in NS?
Jul 23 '05 #1
11 3968
On Fri, 15 Oct 2004 10:45:44 -0400, nntp <nn**@rogers.com> wrote:
Should I use both name and id
<div name="abc" id="abc"> for using getElementById in NS?


No, for two reasons:

1) getElementById only returns references to elements that have a matching
id. Though IE does return matching names, it is broken in this respect[1].
2) The majority of elements do not have name attributes, and those that do
only continue to have them for backward compatibility with old browsers
like NN4. A DIV certainly does not have, nor has it ever had, a name
attribute.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Lee
nntp said:

Should I use both name and id
<div name="abc" id="abc"> for using getElementById in NS?


There is no need for the name attribute for using getElementById
in any browser. All you need is an id.

Form elements should also have a name, if their value is being
submitted.

Jul 23 '05 #3
"nntp" <nn**@rogers.com> writes:
Should I use both name and id
<div name="abc" id="abc"> for using getElementById in NS?


What NS (which I assume means Netscape)?
Not that it matters. Netscape 4 has no getElementById and Netscape 6+
is standards compliant and only finds elements by their "id" using
getElementById.

And there was never a name attribute on div elements. :)

/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 23 '05 #4
I saw it somewhere saying if possible we should use both name and id.
I don't remember if it is about getElementById or something like
frams[blahblah], links, images, forms....
It was saying NS could not find it if we only use name...
I really don't recall it. Anyone has a reference about it?

If i use both name and id, will I get some error, then? such as the same obj
is found twice, or name attribut is not supported?...
nntp said:

Should I use both name and id
<div name="abc" id="abc"> for using getElementById in NS?


There is no need for the name attribute for using getElementById
in any browser. All you need is an id.

Form elements should also have a name, if their value is being
submitted.

Jul 23 '05 #5
nntp wrote:
I saw it somewhere saying if possible we should use both name and id.
I don't remember if it is about getElementById or something like
frams[blahblah], links, images, forms....
It was saying NS could not find it if we only use name...
I really don't recall it. Anyone has a reference about it?

If i use both name and id, will I get some error, then? such as the same obj
is found twice, or name attribut is not supported?...


Why not test it? Its easy enough to do. Then, consult the group FAQ, its
in my signature. The rest might dawn on you also.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #6
Lee wrote:
Form elements should also have a name, if their value is being
submitted.


No they shouldn't. Form _controls_ should.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #7
David Dorward wrote:
Lee wrote:
Form elements should also have a name, if their value is being
submitted.


No they shouldn't. Form _controls_ should.


I'm sure he was referring to the members of the forms.elements[] collection,
which, although somewhat misnamed, are a form's controls.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #8
Lee
Grant Wagner said:

David Dorward wrote:
Lee wrote:
> Form elements should also have a name, if their value is being
> submitted.


No they shouldn't. Form _controls_ should.


I'm sure he was referring to the members of the forms.elements[] collection,
which, although somewhat misnamed, are a form's controls.


Yes, except that I don't consider them to be misnamed.
They are the elements that comprise the form.

Jul 23 '05 #9
On 15 Oct 2004 14:50:47 -0700, Lee <RE**************@cox.net> wrote:
Grant Wagner said:
David Dorward wrote:
Lee wrote:

Form elements should also have a name, if their value is being
submitted.

No they shouldn't. Form _controls_ should.


I'm sure he was referring to the members of the forms.elements[]
collection, which, although somewhat misnamed, are a form's controls.


Yes, except that I don't consider them to be misnamed.
They are the elements that comprise the form.


True, but it can become confusing. Does "form elements" refers to a set of
FORMs, or the elements that the form contains? True, context usually helps
determine which, but I think it's a lot simpler to avoid it altogether by
using "form element" to refer to a FORM, and "form controls" to refer to
INPUT, SELECT, and TEXTAREA elements.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #10
Michael Winter wrote:
determine which, but I think it's a lot simpler to avoid it altogether by
using "form element" to refer to a FORM, and "form controls" to refer to
INPUT, SELECT, and TEXTAREA elements.


Which is what the HTML 4.01 specification does :)

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #11
nntp wrote:
Should I use both name and id
<div name="abc" id="abc"> for using getElementById in NS?

No-one cares. The "name" is (and always was) pretty much irrelevant.
Jul 23 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Carl | last post by:
When using 'name' in the form, it works, when using 'id' it doesn't. Any comments about this? By the way, is this a good method or is it better to use 'getElementById'? Carl <body> <form...
21
by: TheKeith | last post by:
I heard that the name attribute is deprecated in html 4.01 strict. Is it recommended that you use the ID attribute for images along with the getElementById method instead of the old way? Thanks.
12
by: CJ | last post by:
Why won't this work? I am passing the name of the form (I have two that use this validation script) but I keep getting an error. Error reads: "document.which_form.name is null or not an object" ...
6
by: Rich Morey | last post by:
Hi, I have a table where I am altering the layout via javascript to create colspans. I want to then delete the "Extra" cells created by the colspans. I have named the cells "r1c1", "r1c2",...
6
by: Neil Cherry | last post by:
I'm working on a JavaScript program and I'm running into name=blah and id=blah. Sometimes it's one or the other and other times it both. Does anyone have a good reference that can help me figure...
1
by: Invisible Man | last post by:
Thanks for help in advance... I'm trying to change the background of: <li class="noflyout" name="leftnav1"><a href="default.asp">Home </a></li> CSS set it to blue - but want to us JS to...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
6
by: Dick Watson | last post by:
I had a page that works when setup like this: === <form name="frmCalc" action=""> <script type="text/javascript"> function btnCalc_onclick(abc) { return "got here with " + abc; }
7
by: moksha | last post by:
Hi, I am new to javascript and i am facing a problem in coding. plz help me out. I am using javascript for dynamically creating a table row which contains text boxes and radio...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.