name vs id in getElementById in NS

N

nntp

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

Michael Winter

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
 
L

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

Lasse Reichstein Nielsen

nntp said:
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
 
N

nntp

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?...
 
R

Randy Webb

nntp said:
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?
 
G

Grant Wagner

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

Lee

Grant Wagner said:
David said:
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.
 
M

Michael Winter

Grant Wagner said:
David said:
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
 
D

David Dorward

Michael said:
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 :)
 
M

Mark Preston

nntp said:
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.
 

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

No members online now.

Forum statistics

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

Latest Threads

Top