name vs id in getElementById in NS

Discussion in 'Javascript' started by nntp, Oct 15, 2004.

  1. nntp

    nntp Guest

    Should I use both name and id
    <div name="abc" id="abc"> for using getElementById in NS?
    nntp, Oct 15, 2004
    #1
    1. Advertising

  2. On Fri, 15 Oct 2004 10:45:44 -0400, nntp <> 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.
    Michael Winter, Oct 15, 2004
    #2
    1. Advertising

  3. nntp

    Lee Guest

    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.
    Lee, Oct 15, 2004
    #3
  4. "nntp" <> 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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Oct 15, 2004
    #4
  5. nntp

    nntp Guest

    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.
    >
    nntp, Oct 15, 2004
    #5
  6. nntp

    Randy Webb Guest

    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?
    Randy Webb, Oct 15, 2004
    #6
  7. 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
    David Dorward, Oct 15, 2004
    #7
  8. nntp

    Grant Wagner Guest

    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 <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Grant Wagner, Oct 15, 2004
    #8
  9. nntp

    Lee Guest

    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.
    Lee, Oct 15, 2004
    #9
  10. On 15 Oct 2004 14:50:47 -0700, Lee <> 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.
    Michael Winter, Oct 15, 2004
    #10
  11. 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
    David Dorward, Oct 16, 2004
    #11
  12. nntp

    Mark Preston Guest

    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.
    Mark Preston, Oct 18, 2004
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    819
    Roedy Green
    Jan 2, 2006
  2. ding feng
    Replies:
    2
    Views:
    2,804
    ding feng
    Jun 25, 2003
  3. weston
    Replies:
    19
    Views:
    222
  4. Replies:
    7
    Views:
    154
    McKirahan
    Jan 31, 2006
  5. Aquosus
    Replies:
    3
    Views:
    106
    Evertjan.
    Oct 7, 2006
Loading...

Share This Page