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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ton den Hartog

    #1

    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



  • Martin Honnen

    #2
    Re: when use ID and when use NAME in a HTML tag ??



    Ton den Hartog wrote:
    [color=blue]
    > I am confused, when use ID and when use NAME to identify an element in HTML
    > ?[/color]

    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/

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: when use ID and when use NAME in a HTML tag ??

      "Ton den Hartog" <ton.den.hartog .removespam@ton h.net> writes:
      [color=blue]
      > I am confused, when use ID and when use NAME to identify an element in HTML
      > ?[/color]

      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 "metainformatio n 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 - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Douglas Crockford

        #4
        Re: 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[color=blue]
        > ?[/color]

        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.



        Comment

        • Frank Carr

          #5
          Re: when use ID and when use NAME in a HTML tag ??

          "Douglas Crockford" <nospam@covad.n et> wrote in message
          news:b9da8$3fca 2040$44a4afc0$1 8368@msgid.mega newsservers.com ...
          [color=blue]
          > Some browsers used them interchangeably , which is
          > confusing.[/color]

          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
          jfcarr@msn.com



          Comment

          • Dr John Stockton

            #6
            Re: when use ID and when use NAME in a HTML tag ??

            JRS: In article <3fc9fddf$0$148 9$e4fe514c@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 :-
            [color=blue]
            >I am confused, when use ID and when use NAME to identify an element in HTML
            >?[/color]

            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.demo n.co.uk/js-index.htm> JS maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

            Comment

            • F. Da Costa

              #7
              Re: when use ID and when use NAME in a HTML tag ??

              A while ago I printed (yep it still exists) a piece (and its still on my
              desk) called:
              Incompatibiliti es 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:[color=blue]
              > "Douglas Crockford" <nospam@covad.n et> wrote in message
              > news:b9da8$3fca 2040$44a4afc0$1 8368@msgid.mega newsservers.com ...
              >
              >[color=green]
              >>Some browsers used them interchangeably , which is
              >>confusing.[/color]
              >
              >
              > 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.
              >[/color]

              Comment

              • Lasse Reichstein Nielsen

                #8
                Re: when use ID and when use NAME in a HTML tag ??

                "F. Da Costa" <dacosta@xs4all .nl> writes:
                [color=blue]
                > Incompatibiliti es in IE and Netscape: HTML & Javascript.
                >
                > Not sure whether its usefull.
                > Link: http://4guysfromrolla.com/webtech/011200-1.shtml[/color]

                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 - lrn@hotpop.com
                DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                'Faith without judgement merely degrades the spirit divine.'

                Comment

                • F. Kolb

                  #9
                  Re: when use ID and when use NAME in a HTML tag ??

                  "Ton den Hartog" <ton.den.hartog .removespam@ton h.net> wrote in message news:<3fc9fddf$ 0$1489$e4fe514c @news.xs4all.nl >...[color=blue]
                  > I am confused, when use ID and when use NAME to identify an element in HTML
                  > ?
                  >
                  > Ton den Hartog[/color]

                  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.getEl ementsByName" 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 "getElemntsByNa me" !!! ...really NOT that
                  "Standard"-like.

                  so long...

                  Comment

                  • GIMME

                    #10
                    Re: when use ID and when use NAME in a HTML tag ??

                    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" <ton.den.hartog .removespam@ton h.net> wrote in message news:<3fc9fddf$ 0$1489$e4fe514c @news.xs4all.nl >...[color=blue]
                    > I am confused, when use ID and when use NAME to identify an element in HTML
                    > ?
                    >
                    > Ton den Hartog[/color]

                    Comment

                    Working...