getElementByID error...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • drew

    getElementByID error...

    Hi all!

    I have this annoying problem with netscape...
    I'm trying to access a form value by using getElementByID and in NS i
    end up with a null reference.

    The following HTML is the form component that gives me headache:
    <form name='task' ...>
    ....
    <select name='priorityS elect' class='selectwi dth'>
    <option value=''>Choose one</option>
    <option value='1'>Criti cal</option>
    <option value='2'>High</option>
    <option value='3'>Mediu m</option>
    <option value='4'>Low</option>
    </select>
    ....
    </form>

    And the related javascript code:
    if(document.get ElementById("pr ioritySelect"). disabled == false)
    { ... }

    When digging into this I can get the desired information by using
    document.task.p rioritySelect, but that should not be necessary, right?

    I hope that anyone knows how to deal with this problem...

    Regards,
    Drew
  • Jim Dabell

    #2
    Re: getElementByID error...

    drew wrote:
    [color=blue]
    > Hi all!
    >
    > I have this annoying problem with netscape...
    > I'm trying to access a form value by using getElementByID and in NS i
    > end up with a null reference.
    >
    > The following HTML is the form component that gives me headache:
    > <form name='task' ...>
    > ...
    > <select name='priorityS elect' class='selectwi dth'>[/color]

    If you want to use getElementById( ) to access this element, then it needs an
    id attribute:

    <select id="..." ...>


    --
    Jim Dabell

    Comment

    • Richard Cornford

      #3
      Re: getElementByID error...

      "drew" <andreas@crossn et.se> wrote in message
      news:494c863f.0 401150554.79748 5ff@posting.goo gle.com...[color=blue]
      >I have this annoying problem with netscape...
      >I'm trying to access a form value by using getElementByID
      >and in NS i end up with a null reference.
      >
      >The following HTML is the form component that gives me headache:
      > <form name='task' ...>
      > ...
      > <select name='priorityS elect' class='selectwi dth'>[/color]

      This element has no ID attribute.

      <snip>[color=blue]
      >And the related javascript code:
      >if(document.ge tElementById("p rioritySelect") .disabled == false)
      > { ... }[/color]

      The above select element has no ID attribute so what makes you think
      that a method with the name "getElementById " could retrieve a reference
      to it?
      [color=blue]
      >When digging into this I can get the desired information
      >by using document.task.p rioritySelect,[/color]

      Better would be:-

      document.forms['task'].elements['prioritySelect ']

      - as it conforms with the pertinent parts of the W3C HTML DOM
      specification and is supported by every browser that understands what a
      form is (for maximum back compatibility).
      [color=blue]
      >but that should not be necessary, right?[/color]

      If you don't give an element an ID it is unrealistic to expect to be
      able to refer to it by ID.
      [color=blue]
      >I hope that anyone knows how to deal with this problem...[/color]

      Give the element an ID to refer to it by or use a property accessor
      relative to the document.forms collection and the elements collection of
      the form.

      Richard.


      Comment

      • Mark Preston

        #4
        Re: getElementByID error...

        On Thu, 15 Jan 2004 14:08:19 +0000, Jim Dabell
        <jim-usenet@jimdabel l.com> wrote:
        [color=blue]
        >drew wrote:
        >[color=green]
        >> Hi all!
        >>
        >> I have this annoying problem with netscape...
        >> I'm trying to access a form value by using getElementByID and in NS i
        >> end up with a null reference.
        >>
        >> The following HTML is the form component that gives me headache:
        >> <form name='task' ...>
        >> ...
        >> <select name='priorityS elect' class='selectwi dth'>[/color]
        >
        >If you want to use getElementById( ) to access this element, then it needs an
        >id attribute:
        >
        ><select id="..." ...>
        >[/color]
        That does seem the obvious comment...

        Comment

        • Jim Ley

          #5
          Re: getElementByID error...

          On Thu, 15 Jan 2004 14:20:48 -0000, "Richard Cornford"
          <Richard@litote s.demon.co.uk> wrote:[color=blue]
          >If you don't give an element an ID it is unrealistic to expect to be
          >able to refer to it by ID.[/color]

          not in IE!

          a=document.body .firstChild.uni queID;
          el=document.get ElementById(a);
          alert(el+','+el .id)

          gEBI can get objects without ID's...

          (this can actually be useful if you don't want to keep a reference to
          the object to avoid DOM leaks, and are worried about people mutating
          ID's on you...)

          Jim.
          --
          comp.lang.javas cript FAQ - http://jibbering.com/faq/

          Comment

          • Richard Cornford

            #6
            Re: getElementByID error...

            "Jim Ley" <jim@jibbering. com> wrote in message
            news:40086e00.1 9518876@news.ci s.dfn.de...[color=blue]
            >On Thu, 15 Jan 2004 14:20:48 -0000, "Richard Cornford"
            ><Richard@litot es.demon.co.uk> wrote:[color=green]
            >>If you don't give an element an ID it is unrealistic to
            >>expect to be able to refer to it by ID.[/color]
            >
            >not in IE!
            >
            >a=document.bod y.firstChild.un iqueID;
            >el=document.ge tElementById(a) ;
            >alert(el+','+e l.id)[/color]

            Was uniqueID introduced in IE 5.5 or 6? I was a bit alarmed to find that
            all DOM elements also appear in the document.all collection under a
            property name that corresponds to its uniqueID on IE 6. Particularly as
            IE's property accessor resolution is slower the more properties an
            object has and that would nearly double the size of the document.all
            collection.
            [color=blue]
            >gEBI can get objects without ID's...[/color]
            <snip>

            Yes I have noticed, and it looks like gEBI is optimised on IE to look up
            the ID in the document.all collection (returning the first element of
            collections found) and when it looks there it also finds, and returns,
            named elements. But the method name and the W3C specs definitely suggest
            that this is incorrect behaviour.

            Richard.


            Comment

            • Jim Ley

              #7
              Re: getElementByID error...

              On Sat, 17 Jan 2004 14:18:49 -0000, "Richard Cornford"
              <Richard@litote s.demon.co.uk> wrote:
              [color=blue]
              >Yes I have noticed, and it looks like gEBI is optimised on IE to look up
              >the ID in the document.all collection (returning the first element of
              >collections found) and when it looks there it also finds, and returns,
              >named elements.[/color]

              It's only incorrect behaviour if the doctype is an HTML one without an
              internal subset, we know IE doesn't actually read the doctype or parse
              it etc. it just has its own internal one. it's own internal one could
              have NAME as type ID, and therefore all is fine if gEBI returns it.

              Given that most people return invalid documents we definately can't
              complain about DOM behaviour on those, if we return a valid HTML or
              XHTML document that says NAME isn't an ID, then we can complain.

              Jim.
              --
              comp.lang.javas cript FAQ - http://jibbering.com/faq/

              Comment

              • Richard Cornford

                #8
                Re: getElementByID error...

                "Jim Ley" <jim@jibbering. com> wrote in message
                news:4009451f.1 6928672@news.ci s.dfn.de...
                <snip>[color=blue]
                >Given that most people return invalid documents we definately
                >can't complain about DOM behaviour on those, if we return a
                >valid HTML or XHTML document that says NAME isn't an ID, then
                >we can complain.[/color]

                I always forget that HTML can be valid and unusual if it has its own
                custom DTD. Or more precisely, I don't forget I just disregard the
                possibility as I see little reason for doing that, and it wouldn't alter
                the scriptability of the resulting DOM in HTML browsers (because, as you
                say, they aren’t interested in the DTD anyway).

                OK, gEBI should be expected to have its W3C Core DOM specified behaviour
                in a valid HTML 4 (with standard DTD) document, but should anything be
                expected from an invalid document?

                Richard


                Comment

                • Jim Ley

                  #9
                  Re: getElementByID error...

                  On Sun, 18 Jan 2004 07:06:28 -0000, "Richard Cornford"
                  <Richard@litote s.demon.co.uk> wrote:
                  [color=blue]
                  > but should anything be
                  >expected from an invalid document?[/color]

                  All bets are off on invalid documents. Standards can only really talk
                  about what conforming user agents do to its own valid documents.

                  Invalid documents could simply be adhering to a different standard,
                  and text/html puts no limits on what can be served as it.

                  Jim.
                  --
                  comp.lang.javas cript FAQ - http://jibbering.com/faq/

                  Comment

                  Working...