IE not grabbing SELECT value

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

    #1

    IE not grabbing SELECT value

    I have a page showing dynamic generation of a SELECT box using
    JavaScript. See http://www.softouch.on.ca/dynamic.html.

    Using Mozilla et al, choosing an option from both lists will result in
    the correct response when 'Show Me' is clicked. But IE only shows the
    result from the first SELECT box. Any ideas why / how to fix this?

    The function I'm using:
    function updateList(what )
    {
    // This dynamically populates the CurrentPosition Picks select box in
    the resume page
    // depending on what one was selected in the LevelOne select box.
    for (var i=0;i<document. Resume.CurrentP ositionPicks.le ngth;i++) //
    empty the list
    {
    document.Resume .CurrentPositio nPicks.options. length=0;
    }

    // LevelOnePicks is the top level select box in the resume form
    // CurrentPosition Picks is the dynamically generated select list
    var CurrentPosition Picks=document. Resume.CurrentP ositionPicks;
    for (var i=0;i<document. Resume.LevelOne Picks.length;i+ +)
    {
    if (document.Resum e.LevelOnePicks .options[i].selected)
    {
    var ThisList=eval(T opLevel[i].Name); // get the array name to use
    for (var j=0; j < ThisList.length ; j++)
    {
    CurrentPosition Picks.options[j]=new Option;
    CurrentPosition Picks.options[j].text=ThisList[j];
    }
    }
    }
    }
  • RobB

    #2
    Re: IE not grabbing SELECT value

    Amer Neely wrote:[color=blue]
    > I have a page showing dynamic generation of a SELECT box using
    > JavaScript. See http://www.softouch.on.ca/dynamic.html.
    >
    > Using Mozilla et al, choosing an option from both lists will result[/color]
    in[color=blue]
    > the correct response when 'Show Me' is clicked. But IE only shows the[/color]
    [color=blue]
    > result from the first SELECT box. Any ideas why / how to fix this?
    >
    > The function I'm using:
    > function updateList(what )
    > {
    > // This dynamically populates the CurrentPosition Picks select box in[/color]
    [color=blue]
    > the resume page
    > // depending on what one was selected in the LevelOne select box.
    > for (var i=0;i<document. Resume.CurrentP ositionPicks.le ngth;i++) //
    > empty the list
    > {
    > document.Resume .CurrentPositio nPicks.options. length=0;
    > }
    >
    > // LevelOnePicks is the top level select box in the resume form
    > // CurrentPosition Picks is the dynamically generated select list
    > var CurrentPosition Picks=document. Resume.CurrentP ositionPicks;
    > for (var i=0;i<document. Resume.LevelOne Picks.length;i+ +)
    > {
    > if (document.Resum e.LevelOnePicks .options[i].selected)
    > {
    > var ThisList=eval(T opLevel[i].Name); // get the array name to use
    > for (var j=0; j < ThisList.length ; j++)
    > {
    > CurrentPosition Picks.options[j]=new Option;
    > CurrentPosition Picks.options[j].text=ThisList[j];
    > }
    > }
    > }
    > }[/color]

    The two browsers handle multiple selects differently. To get selected
    option values/texts cross-browser, you need to loop the options and
    examine them. In addition, your updateList() function isn't setting
    option values, just displayed text. Some browsers will substitute the
    latter for the former but, don't rely on it...set both.

    function Output()
    {
    var o,
    picked = [],
    msel = document.Resume .CurrentPositio nPicks;
    for (var i = 0, l = msel.length; i < l; ++i)
    {
    if ((o = msel.options[i]).selected)
    picked.push(o.t ext);
    }
    alert(
    'You chose\n' +
    document.Resume .LevelOnePicks. value +
    ':' +
    picked.join(' | ')
    );
    }

    Matt Kruse will now plug his script. #:=D

    Comment

    • Mick White

      #3
      Re: IE not grabbing SELECT value

      Amer Neely wrote:
      [color=blue]
      > I have a page showing dynamic generation of a SELECT box using
      > JavaScript. See http://www.softouch.on.ca/dynamic.html.
      >
      > Using Mozilla et al, choosing an option from both lists will result in
      > the correct response when 'Show Me' is clicked. But IE only shows the
      > result from the first SELECT box. Any ideas why / how to fix this?
      >
      > The function I'm using:[/color]

      I would use a simpler technique:

      <script type="text/javascript">
      window["night spots"]=["Café Royale","Maxim' s","Rose and Crown"];
      cars=["ford","dodge", "buick"];
      countries=["USA","UK","Eas t Timor"];

      function populateMenuWit hArray(menu,arr ay){
      var alen=array.leng th;
      menu.options.le ngth=0;
      for(var i=0;i<alen;i++) {
      menu.options[i]=new Option(array[i],array[i]);
      }
      }

      </script>

      <form action="some.ht ml" method="get" name="f">
      <select name="a" onchange=
      "if(this.select edIndex)
      populateMenuWit hArray(this.for m.b,
      window[this[this.selectedIn dex].text]);">
      <option selected>Select One</option>
      <option>cars</option>
      <option>countri es</option>
      <option>night spots</option>
      </select>
      <select name="b"></select>
      Mick (tested)

      snip

      Comment

      • Amer Neely

        #4
        Re: IE not grabbing SELECT value

        Mick White wrote:
        [color=blue]
        > Amer Neely wrote:
        >[color=green]
        >> I have a page showing dynamic generation of a SELECT box using
        >> JavaScript. See http://www.softouch.on.ca/dynamic.html.
        >>
        >> Using Mozilla et al, choosing an option from both lists will result in
        >> the correct response when 'Show Me' is clicked. But IE only shows the
        >> result from the first SELECT box. Any ideas why / how to fix this?
        >>
        >> The function I'm using:[/color]
        >
        >
        > I would use a simpler technique:
        >
        > <script type="text/javascript">
        > window["night spots"]=["Café Royale","Maxim' s","Rose and Crown"];
        > cars=["ford","dodge", "buick"];
        > countries=["USA","UK","Eas t Timor"];
        >
        > function populateMenuWit hArray(menu,arr ay){
        > var alen=array.leng th;
        > menu.options.le ngth=0;
        > for(var i=0;i<alen;i++) {
        > menu.options[i]=new Option(array[i],array[i]);
        > }
        > }
        >
        > </script>
        >
        > <form action="some.ht ml" method="get" name="f">
        > <select name="a" onchange=
        > "if(this.select edIndex)
        > populateMenuWit hArray(this.for m.b,
        > window[this[this.selectedIn dex].text]);">
        > <option selected>Select One</option>
        > <option>cars</option>
        > <option>countri es</option>
        > <option>night spots</option>
        > </select>
        > <select name="b"></select>
        > Mick (tested)
        >
        > snip[/color]

        Thanks for the quick response - I do like your simpler function. But IE
        still only shows the second SELECT box choice.

        I'm going to try the suggestion by RobB about looping through the list
        boxes.

        Comment

        • Amer Neely

          #5
          Re: IE not grabbing SELECT value

          RobB wrote:
          [color=blue]
          > Amer Neely wrote:
          >[color=green]
          >>I have a page showing dynamic generation of a SELECT box using
          >>JavaScript. See http://www.softouch.on.ca/dynamic.html.
          >>
          >>Using Mozilla et al, choosing an option from both lists will result[/color]
          >
          > in
          >[color=green]
          >>the correct response when 'Show Me' is clicked. But IE only shows the[/color]
          >
          >[color=green]
          >>result from the first SELECT box. Any ideas why / how to fix this?
          >>
          >>The function I'm using:
          >>function updateList(what )
          >>{
          >> // This dynamically populates the CurrentPosition Picks select box in[/color]
          >
          >[color=green]
          >>the resume page
          >> // depending on what one was selected in the LevelOne select box.
          >> for (var i=0;i<document. Resume.CurrentP ositionPicks.le ngth;i++) //
          >>empty the list
          >> {
          >> document.Resume .CurrentPositio nPicks.options. length=0;
          >> }
          >>
          >> // LevelOnePicks is the top level select box in the resume form
          >> // CurrentPosition Picks is the dynamically generated select list
          >> var CurrentPosition Picks=document. Resume.CurrentP ositionPicks;
          >> for (var i=0;i<document. Resume.LevelOne Picks.length;i+ +)
          >> {
          >> if (document.Resum e.LevelOnePicks .options[i].selected)
          >> {
          >> var ThisList=eval(T opLevel[i].Name); // get the array name to use
          >> for (var j=0; j < ThisList.length ; j++)
          >> {
          >> CurrentPosition Picks.options[j]=new Option;
          >> CurrentPosition Picks.options[j].text=ThisList[j];
          >> }
          >> }
          >> }
          >>}[/color]
          >
          >
          > The two browsers handle multiple selects differently. To get selected
          > option values/texts cross-browser, you need to loop the options and
          > examine them. In addition, your updateList() function isn't setting
          > option values, just displayed text. Some browsers will substitute the
          > latter for the former but, don't rely on it...set both.
          >
          > function Output()
          > {
          > var o,
          > picked = [],
          > msel = document.Resume .CurrentPositio nPicks;
          > for (var i = 0, l = msel.length; i < l; ++i)
          > {
          > if ((o = msel.options[i]).selected)
          > picked.push(o.t ext);
          > }
          > alert(
          > 'You chose\n' +
          > document.Resume .LevelOnePicks. value +
          > ':' +
          > picked.join(' | ')
          > );
          > }
          >
          > Matt Kruse will now plug his script. #:=D
          >[/color]

          Ah, that figures. Thanks for the direction and the sample code.

          Comment

          • Amer Neely

            #6
            Re: IE not grabbing SELECT value

            RobB wrote:
            [color=blue]
            > Amer Neely wrote:
            >[color=green]
            >>I have a page showing dynamic generation of a SELECT box using
            >>JavaScript. See http://www.softouch.on.ca/dynamic.html.
            >>
            >>Using Mozilla et al, choosing an option from both lists will result[/color]
            >
            > in
            >[color=green]
            >>the correct response when 'Show Me' is clicked. But IE only shows the[/color]
            >
            >[color=green]
            >>result from the first SELECT box. Any ideas why / how to fix this?
            >>
            >>The function I'm using:
            >>function updateList(what )
            >>{
            >> // This dynamically populates the CurrentPosition Picks select box in[/color]
            >
            >[color=green]
            >>the resume page
            >> // depending on what one was selected in the LevelOne select box.
            >> for (var i=0;i<document. Resume.CurrentP ositionPicks.le ngth;i++) //
            >>empty the list
            >> {
            >> document.Resume .CurrentPositio nPicks.options. length=0;
            >> }
            >>
            >> // LevelOnePicks is the top level select box in the resume form
            >> // CurrentPosition Picks is the dynamically generated select list
            >> var CurrentPosition Picks=document. Resume.CurrentP ositionPicks;
            >> for (var i=0;i<document. Resume.LevelOne Picks.length;i+ +)
            >> {
            >> if (document.Resum e.LevelOnePicks .options[i].selected)
            >> {
            >> var ThisList=eval(T opLevel[i].Name); // get the array name to use
            >> for (var j=0; j < ThisList.length ; j++)
            >> {
            >> CurrentPosition Picks.options[j]=new Option;
            >> CurrentPosition Picks.options[j].text=ThisList[j];
            >> }
            >> }
            >> }
            >>}[/color]
            >
            >
            > The two browsers handle multiple selects differently. To get selected
            > option values/texts cross-browser, you need to loop the options and
            > examine them. In addition, your updateList() function isn't setting
            > option values, just displayed text. Some browsers will substitute the
            > latter for the former but, don't rely on it...set both.
            >
            > function Output()
            > {
            > var o,
            > picked = [],
            > msel = document.Resume .CurrentPositio nPicks;
            > for (var i = 0, l = msel.length; i < l; ++i)
            > {
            > if ((o = msel.options[i]).selected)
            > picked.push(o.t ext);
            > }
            > alert(
            > 'You chose\n' +
            > document.Resume .LevelOnePicks. value +
            > ':' +
            > picked.join(' | ')
            > );
            > }
            >
            > Matt Kruse will now plug his script. #:=D
            >[/color]

            This solution worked perfectly (but I changed the order of display).
            Thanks again.

            Comment

            • Mick White

              #7
              Re: IE not grabbing SELECT value

              Amer Neely wrote:
              [color=blue]
              > Mick White wrote:[/color]
              [color=blue][color=green]
              >>
              >> function populateMenuWit hArray(menu,arr ay){
              >> var alen=array.leng th;
              >> menu.options.le ngth=0;
              >> for(var i=0;i<alen;i++) {
              >> menu.options[i]=new Option(array[i],array[i]);
              >> }
              >> }
              >>
              >> </script>[/color][/color]
              [color=blue][color=green]
              >> snip[/color]
              >
              >
              > Thanks for the quick response - I do like your simpler function. But IE
              > still only shows the second SELECT box choice.
              >
              > I'm going to try the suggestion by RobB about looping through the list
              > boxes.[/color]



              Works for me, IE 5.2(Mac), FF 1.0(mac), Moz 1.7.3(Mac), Safari 1.03
              Mick

              Comment

              Working...