Looping to populate selections for IE & Firefox

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

    Looping to populate selections for IE & Firefox

    <script>

    function filldims()
    {
    var objSelect = document.getEle mentById("id_in twidth");
    objSelect.optio ns.length = 0;

    for(var i = 20; i < 31; i++)
    {
    var objOption = document.create Element("option ");
    objOption.text = i;
    objOption.value = i;

    //the following line WORKS IN FIREFOX ONLY
    objSelect.add(o bjOption,
    objSelect.optio ns[objSelect.optio ns.length]);


    };
    }

    </script>
  • Thomas 'PointedEars' Lahn

    #2
    Re: Looping to populate selections for IE &amp; Firefox

    Rick W. wrote:
    //the following line WORKS IN FIREFOX ONLY
    objSelect.add(o bjOption,
    objSelect.optio ns[objSelect.optio ns.length]);
    That is incorrect. It works in all user agents that have the object
    referred to by `objSelect' implement the HTMLSelectEleme nt interface
    of W3C DOM Level 2 HTML. However, it should be noted that passing
    `null' for the second argument suffices here:

    <http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-14493106>


    PointedEars
    --
    var bugRiddenCrashP ronePieceOfJunk = (
    navigator.userA gent.indexOf('M SIE 5') != -1
    && navigator.userA gent.indexOf('M ac') != -1
    ) // Plone, register_functi on.js:16

    Comment

    • Rick W.

      #3
      Re: Looping to populate selections for IE &amp; Firefox

      I added the 'null' but it still didn't work.
      but if you look closer I AM passing two parameters already.

      In IE, I do get a list of blank items.
      another words, the list is now 10 items long, but the list has blank
      values in it.

      Rick

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Looping to populate selections for IE &amp; Firefox

        Rick W. wrote:
        I added the 'null' but it still didn't work.
        Nobody said anything about *adding* `null'. I suggested you should
        *replace* the second argument with `null' because it is more efficient (and
        less error-prone) than retrieving an (obviously) non-existing reference
        through a property access.
        but if you look closer I AM passing two parameters already.
        If you look closer, nobody debated that in the first place.
        In IE, I do get a list of blank items. another words, the list is now 10
        items long, but the list has blank values in it.
        Nobody debated that IE does not implement the HTMLSelectEleme nt interface
        for its Select objects either.

        Since apparently you don't see the problem, I would like to point out to you
        that your posting completely lacks a question.

        Please read the FAQ carefully: <http://jibbering.com/faq/>

        And it wouldn't hurt to post under your full name, Rick W. #4711.


        PointedEars
        --
        realism: HTML 4.01 Strict
        evangelism: XHTML 1.0 Strict
        madness: XHTML 1.1 as application/xhtml+xml
        -- Bjoern Hoehrmann

        Comment

        • Richard Maher

          #5
          Re: Looping to populate selections for IE &amp; Firefox

          Hi Rick,
          //the following line WORKS IN FIREFOX ONLY
          Might not be of any use to you, but I use this sort of thing: -

          queList = document.queOpt ions.queList;
          : : :
          queList.length = zeros;
          queList.options[queList.length] = new Option (msgQue, msgQue);
          OR
          selectRef = document.getJob s.jobList;
          selectClone = selectRef.clone Node(true);
          : : :
          selectRef.size = 1;
          swapClone = selectClone.clo neNode(true);
          selectRef.paren tNode.replaceCh ild(swapClone, selectRef);
          selectRef = document.getJob s.jobList;
          : : :
          selectRef.optio ns[selectRef.optio ns.length] = new Option (jobMsg,
          jobMsg);

          For complete example code please see: -
          http://manson.vistech. net/t3$examples/demo_client_web .html

          Username: TIER3_DEMO
          Password: QUEUE

          Enter "*" asterix for the Queue Name and then hit "Get Job Info"

          All source can be found at: -
          http://manson.vistech. net/t3$examples/

          Cheers Richard Maher

          "Rick W." <RickWarda@sbcg lobal.netwrote in message
          news:c581d17c-336a-4788-955f-3621d29d7c3d@e1 g2000pra.google groups.com...
          <script>
          >
          function filldims()
          {
          var objSelect = document.getEle mentById("id_in twidth");
          objSelect.optio ns.length = 0;
          >
          for(var i = 20; i < 31; i++)
          {
          var objOption = document.create Element("option ");
          objOption.text = i;
          objOption.value = i;
          >
          //the following line WORKS IN FIREFOX ONLY
          objSelect.add(o bjOption,
          objSelect.optio ns[objSelect.optio ns.length]);
          >
          >
          };
          }
          >
          </script>

          Comment

          • SAM

            #6
            Re: Looping to populate selections for IE &amp; Firefox

            Le 11/3/08 8:53 PM, Rick W. a écrit :
            <script>
            >
            function filldims()
            {
            var objSelect = document.getEle mentById("id_in twidth");
            objSelect.optio ns.length = 0;
            >
            for(var i = 20; i < 31; i++)
            {
            var objOption = document.create Element("option ");
            objOption.text = i;
            objOption.value = i;
            >
            //the following line WORKS IN FIREFOX ONLY
            objSelect.add(o bjOption,
            objSelect.optio ns[objSelect.optio ns.length]);
            objSelect.appen dChild(objOptio n); // would have to work
            >
            };
            }

            function filldims()
            {
            var objSelect = document.getEle mentById("id_in twidth");
            objSelect.optio ns.length = 0;

            for(var i = 20; i < 31; i++)
            {
            objSelect.optio ns[objSelect.optio ns.length] = new Option(i,i);
            }
            }
            </script>

            Comment

            • Stanimir Stamenkov

              #7
              Re: Looping to populate selections for IE &amp; Firefox

              Mon, 3 Nov 2008 11:53:26 -0800 (PST), /Rick W./:
              function filldims()
              {
              var objSelect = document.getEle mentById("id_in twidth");
              objSelect.optio ns.length = 0;
              >
              for(var i = 20; i < 31; i++)
              {
              var objOption = document.create Element("option ");
              objOption.text = i;
              objOption.value = i;
              >
              //the following line WORKS IN FIREFOX ONLY
              objSelect.add(o bjOption,
              objSelect.optio ns[objSelect.optio ns.length]);
              The line actually works in all standard-compliant [1] browsers, but
              Internet Explorer (as already pointed out in another reply). Try
              using just:

              objSelect.add(o bjOption);

              IE versions prior 8 expect an optional index [2] and not an object
              reference as a second argument.
              >
              };
              }
              [1] http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-14493106
              [2] http://msdn.microsoft.com/library/ms...us,VS.85).aspx

              --
              Stanimir

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: Looping to populate selections for IE &amp; Firefox

                Stanimir Stamenkov wrote:
                Mon, 3 Nov 2008 11:53:26 -0800 (PST), /Rick W./:
                > //the following line WORKS IN FIREFOX ONLY
                > objSelect.add(o bjOption,
                >objSelect.opti ons[objSelect.optio ns.length]);
                >
                The line actually works in all standard-compliant [1] browsers, but
                Internet Explorer (as already pointed out in another reply). Try
                using just:
                >
                objSelect.add(o bjOption);
                Bad advice. The second argument of HTMLSelectEleme nt::add() is mandatory;
                with the call above you are risking an exception along the lines of "not
                enough arguments".
                IE versions prior 8 expect an optional index [2] and not an object
                reference as a second argument.
                So it would appear to be a viable approach, unless MSHTML < 8 throws
                exceptions then, to pass `null' for the second argument, check the `value'
                or `text' of the newly added item, and modify its `value' and `text'
                properties when necessary.

                However, there is also a well-documented proprietary, but apparently
                cross-browser approach (originating from "DOM Level 0"):

                var opts = sel.options;
                opts[opts.length] =
                new Option("text", "value, defaultSelected , selected);

                whereas the second argument is optional, and `defaultSelecte d' and
                `selected' are optional boolean values that have the meaning of their
                identifiers.


                PointedEars
                --
                realism: HTML 4.01 Strict
                evangelism: XHTML 1.0 Strict
                madness: XHTML 1.1 as application/xhtml+xml
                -- Bjoern Hoehrmann

                Comment

                • Rick W.

                  #9
                  Re: Looping to populate selections for IE &amp; Firefox

                  Thank you SAM
                  Your solution appears to work fine in both browsers.

                  I'm going to go with it.
                  Hopefully there are no hidden issues with this approach that I
                  inevitably find out later.

                  Thanks again,
                  Rick

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Looping to populate selections for IE &amp; Firefox

                    Rick W. wrote:
                    Thank you SAM
                    Your solution appears to work fine in both browsers.
                    IE 6 and IE 7, I presume ...

                    To learn you have a lot, young apprentice.


                    PointedEars
                    --
                    Prototype.js was written by people who don't know javascript for people
                    who don't know javascript. People who don't know javascript are not
                    the best source of advice on designing systems that use javascript.
                    -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

                    Comment

                    Working...