Won't work in IE

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

    #1

    Won't work in IE

    There is probably a easy answer to this. I want to get the value of
    the selection in a listbox. The following code works happily in
    mozilla but not in IE.

    var selElem = window.document .getElementById (Type);
    //Type is a variable name that is the same as whats on
    the form
    var selIndex = selElem.selecte dIndex;
    Type = selElem.options[selIndex].value;

    I think its the last line thats the problem.

    Thanks all.
  • Lasse Reichstein Nielsen

    #2
    Re: Won't work in IE

    nsm38@student.c pit.ac.nz (nadia) writes:
    [color=blue]
    > There is probably a easy answer to this. I want to get the value of
    > the selection in a listbox. The following code works happily in
    > mozilla but not in IE.[/color]

    Which IE?
    [color=blue]
    > var selElem = window.document .getElementById (Type);
    > //Type is a variable name that is the same as whats on
    > the form
    > var selIndex = selElem.selecte dIndex;
    > Type = selElem.options[selIndex].value;
    >
    > I think its the last line thats the problem.[/color]

    I don't. It looks fine to me.

    What error message do you get (not that IE's error messages are that good)?
    Are you sure that selElem is found correctly?

    Where is Type set and used?

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • nadia

      #3
      Re: Won't work in IE

      Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<vfraka4k. fsf@hotpop.com> ...
      [color=blue]
      >
      > Which IE?[/color]

      6.0 (I haven't checked with other versions)
      [color=blue]
      >[color=green]
      > > var selElem = window.document .getElementById (Type);
      > > //Type is a variable name that is the same as whats on
      > > the form
      > > var selIndex = selElem.selecte dIndex;
      > > Type = selElem.options[selIndex].value;
      > >
      > > I think its the last line thats the problem.[/color]
      >
      > I don't. It looks fine to me.
      >
      > What error message do you get (not that IE's error messages are that good)?
      > Are you sure that selElem is found correctly?[/color]

      It doesn't give me any error messages, When I tried to debug it
      selIndex returned the correct number. Type just returns nothing.[color=blue]
      >
      > Where is Type set and used?
      >[/color]
      Type is set just above the code with :
      var Type = 'lsType' + i; //i is a number passed in to the function to
      identify
      //the unique id of a list box
      :=) Nadia

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Won't work in IE

        nsm38@student.c pit.ac.nz (nadia) writes:
        [color=blue][color=green][color=darkred]
        > > > Type = selElem.options[selIndex].value;[/color][/color][/color]
        [color=blue][color=green][color=darkred]
        > > > I think its the last line thats the problem.[/color][/color][/color]
        [color=blue][color=green]
        > > Where is Type set and used?[/color][/color]
        [color=blue]
        > Type is set just above the code with :
        > var Type = 'lsType' + i; //i is a number passed in to the function to
        > identify
        > //the unique id of a list box[/color]

        So it is a local variable, only visible inside the function. You then
        set it to the value of the selected option of the select element ...
        and where is it used? Do you return the value?

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • nadia

          #5
          Re: Won't work in IE

          This is the full code:

          Javascript in the header:
          <script type="text/javascript" language = "javascript ">
          Names = new Array();
          Names["Browser"] = ['Any', 'Netscape Communicator', 'Ms-internet
          explorer', 'Opera', 'Amaya', 'Mozilla'];
          Names["Operating System"] = ['pc-dos', 'ms-windows', 'macOS', 'unix',
          'muli-os', 'none'];
          Names["none"] = ['none'];

          function swapName(form, i) {
          var Type = 'lsType' + i;
          var Name = 'lsName' + i;

          //select the type lsbox
          var selElem = window.document .getElementById (Type);
          var selIndex = selElem.selecte dIndex;
          //get the value of the selected item in the lsType box
          Type = selElem.options[selIndex].value;

          //select the Name lsBox
          selElem = window.document .getElementById (Name);
          // this bit resets the name select list to nothing.
          while (selElem.option s.length > 0) selElem.options[0] = null;

          // this bit populates the name select list with the required Names.
          if (Type.length > 0) {

          var current_array = Names[Type];
          for (j=0;j<current_ array.length;j+ +) {

          var optionName = new Option(current_ array[j],
          current_array[j], false, false);
          //var optionName = new Option('hello', 'hello', false, false);
          selElem.options[selElem.options .length] = optionName;
          }
          }
          }
          </script>

          HTML in the body (generated from a php script):
          <select name="lsType[]" onChange="swapN ame(this.form,0 )" id="lsType0">
          <option>none
          <option>Operati ng System
          <option>Brows er
          </select>
          <select name="lsName[]" id="lsName0"></select>

          Comment

          • W d'Anjos

            #6
            Re: Won't work in IE

            Replace line:

            Type = selElem.options[selIndex].value;

            By

            Type = selElem.options[selIndex].text;


            I hope this helps.

            Wagner

            Comment

            • nadia

              #7
              Re: Won't work in IE

              Thanks, Works fine.

              Thought it was something simple

              Comment

              Working...