IE 7 Select Box Issue

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

    IE 7 Select Box Issue

    I have a web page with 2 html multiple select boxes on it, and I use
    javascript to dynamicaly copy options from one box to another, before
    deleting the option from the first box.

    My issue is that in IE 7 more often than not after the option value has
    been deleted

    form.selone.opt ions[index] = null;

    the select box resets to the first item in the list, meaning that the
    user has to search through the select box again to find the place they
    where previously.

    This did not occur in IE6 or Mozilla.

    The only solution I can find is to set the selectedIndex to the
    previous item in the list howeer, this is not ideal.

    form.selone.sel ectedIndex = index-1;

    Any ideas would be appreciated.

  • ASM

    #2
    Re: IE 7 Select Box Issue

    srt5k a écrit :
    The only solution I can find is to set the selectedIndex to the
    previous item in the list howeer, this is not ideal.
    >
    form.selone.sel ectedIndex = index-1;
    it seems ok
    Any ideas would be appreciated.
    without giving the complete code of your copyToDeleteMe function
    ....
    no

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date

    Comment

    • RobG

      #3
      Re: IE 7 Select Box Issue


      srt5k wrote:
      I have a web page with 2 html multiple select boxes on it, and I use
      javascript to dynamicaly copy options from one box to another, before
      deleting the option from the first box.
      You don't have to copy and delete, just assign the option to the other
      select, e.g.:

      <select id="selA">
      <option>selA 0
      <option>selA 1
      <option>selA 2
      <option>selA 3
      </select>

      <select id="selB">
      <option>selB 0
      <option>selB 1
      <option>selB 2
      <option>selB 3
      </select>

      <button onclick="
      var a = document.getEle mentById('selA' );
      var b = document.getEle mentById('selB' );
      var idx = a.selectedIndex ;
      b.options[b.options.lengt h] = a.options[idx];
      a.selectedIndex = (idx 0)? idx-1 : 0;
      ">Move selected A to B</button>

      --
      Rob

      Comment

      • srt5k

        #4
        Re: IE 7 Select Box Issue

        Thanks

        I want to remove the option from the previous box so that the user can
        only select it once. - This feature only occurs in IE7 - IE6 and
        mozilla keeps the first select box scroll bar at the same position in
        the select box while IE7 resets it to the top of the list again.

        Sorry code as follows...

        <html>
        <head>
        <script language="JavaS cript">

        function moveOption(form ) {

        if(form.selone. selectedIndex == -1){
        alert("Please select an Option");
        }else{

        for (var i=0; i<form.selone.o ptions.length;i ++)
        {

        if (form.selone.op tions[i].selected)
        {

        addOption(form. seltwo,form.sel one.options[i].text,form.selo ne.options[i].value);
        deleteOption(fo rm.selone,i);
        }
        }
        }
        }


        function addOption(objec t,text,value) {

        var defaultSelected = true;
        var selected = true;
        var optionName = new Option(text, value, defaultSelected ,
        selected)
        object.options[object.length] = optionName;
        }

        function deleteOption(ob ject,index) {
        object.options[index] = null;
        }



        </script>

        </head>
        <body>
        <form name="frmMain">
        <select name="selone" size="5" style="width:18 0;height:100;">
        <option value=0>0</option>
        <option value=10>10</option>
        <option value=20>20</option>
        <option value=30>30</option>
        <option value=40>40</option>
        <option value=50>50</option>
        <option value=60>60</option>
        <option value=70>70</option>
        <option value=80>80</option>
        <option value=90>90</option>
        <option value=100>100</option>
        </select>

        Button
        <input type="button" name="BtnAdd" value=">>"
        onClick="moveOp tion(frmMain);" >

        <select name="seltwo" size="5" style="width:18 0;height:100;">
        </select>



        </form>
        </body>
        </html>





        RobG wrote:
        srt5k wrote:
        I have a web page with 2 html multiple select boxes on it, and I use
        javascript to dynamicaly copy options from one box to another, before
        deleting the option from the first box.
        >
        You don't have to copy and delete, just assign the option to the other
        select, e.g.:
        >
        <select id="selA">
        <option>selA 0
        <option>selA 1
        <option>selA 2
        <option>selA 3
        </select>
        >
        <select id="selB">
        <option>selB 0
        <option>selB 1
        <option>selB 2
        <option>selB 3
        </select>
        >
        <button onclick="
        var a = document.getEle mentById('selA' );
        var b = document.getEle mentById('selB' );
        var idx = a.selectedIndex ;
        b.options[b.options.lengt h] = a.options[idx];
        a.selectedIndex = (idx 0)? idx-1 : 0;
        ">Move selected A to B</button>
        >
        --
        Rob

        Comment

        • Duncan Booth

          #5
          Re: IE 7 Select Box Issue

          "RobG" <rgqld@iinet.ne t.auwrote:
          srt5k wrote:
          >I have a web page with 2 html multiple select boxes on it, and I use
          >javascript to dynamicaly copy options from one box to another, before
          >deleting the option from the first box.
          >
          You don't have to copy and delete, just assign the option to the other
          select, e.g.:
          >
          <select id="selA">
          <option>selA 0
          <option>selA 1
          <option>selA 2
          <option>selA 3
          </select>
          >
          <select id="selB">
          <option>selB 0
          <option>selB 1
          <option>selB 2
          <option>selB 3
          </select>
          >
          <button onclick="
          var a = document.getEle mentById('selA' );
          var b = document.getEle mentById('selB' );
          var idx = a.selectedIndex ;
          b.options[b.options.lengt h] = a.options[idx];
          a.selectedIndex = (idx 0)? idx-1 : 0;
          ">Move selected A to B</button>
          >
          I bet you didn't test that on IE.

          IE won't let you assign an option to more than one select box at a time.
          You'll get a javascript error if you try. You can possibly get away with:

          var opt = a.options[idx];
          a.options[idx] = null;
          b.options[b.options.lengt h] = opt;

          except I have a vague memory that with IE6 reusing options can sometimes go
          horribly wrong. Previously I've ended up storing an array of [value,label]
          pairs and creating a new option element each time I want to use it. Sorry I
          can't remember the details of the problem. If I'm correct about there being
          issues then the OP's copying is probably the safest way of avoiding
          trouble.

          Comment

          • srt5k

            #6
            Re: IE 7 Select Box Issue


            Think it has been tested in IE

            It doesn't use the same option twice it creates a new option based on
            the existing 1

            var optionName = new Option(text, value, defaultSelected ,
            selected)

            It has been working fine for a couple of years but I have only been
            getting issues when some users started using IE7.



            Duncan Booth wrote:
            "RobG" <rgqld@iinet.ne t.auwrote:
            >
            srt5k wrote:
            I have a web page with 2 html multiple select boxes on it, and I use
            javascript to dynamicaly copy options from one box to another, before
            deleting the option from the first box.
            You don't have to copy and delete, just assign the option to the other
            select, e.g.:

            <select id="selA">
            <option>selA 0
            <option>selA 1
            <option>selA 2
            <option>selA 3
            </select>

            <select id="selB">
            <option>selB 0
            <option>selB 1
            <option>selB 2
            <option>selB 3
            </select>

            <button onclick="
            var a = document.getEle mentById('selA' );
            var b = document.getEle mentById('selB' );
            var idx = a.selectedIndex ;
            b.options[b.options.lengt h] = a.options[idx];
            a.selectedIndex = (idx 0)? idx-1 : 0;
            ">Move selected A to B</button>
            >
            I bet you didn't test that on IE.
            >
            IE won't let you assign an option to more than one select box at a time.
            You'll get a javascript error if you try. You can possibly get away with:
            >
            var opt = a.options[idx];
            a.options[idx] = null;
            b.options[b.options.lengt h] = opt;
            >
            except I have a vague memory that with IE6 reusing options can sometimes go
            horribly wrong. Previously I've ended up storing an array of [value,label]
            pairs and creating a new option element each time I want to use it. Sorry I
            can't remember the details of the problem. If I'm correct about there being
            issues then the OP's copying is probably the safest way of avoiding
            trouble.

            Comment

            • Duncan Booth

              #7
              Re: IE 7 Select Box Issue

              "srt5k" <spam@sr-taylor.co.ukwro te:
              >
              Think it has been tested in IE
              Not your code, it's the code RobG posted that doesn't work on IE.
              >
              It doesn't use the same option twice it creates a new option based on
              the existing 1
              Yes, and I'm simply saying that, contrary to what RobG said you do actually
              have to do that to get it to work on IE.

              On your original point, I think you do have to set the selectedIndex to
              something, either the previous or next element in the list. I agree with
              you its annoying, but I think you will have to do it to be sure of
              consistent behaviour.

              Comment

              • srt5k

                #8
                Re: IE 7 Select Box Issue


                That's great thanks Duncan,

                Yeah think I'll either have to live with setting the selctedIndex to
                the previous item, or I might try and replicate it with css &
                javascript.

                Thanks


                Duncan Booth wrote:
                "srt5k" <spam@sr-taylor.co.ukwro te:
                >

                Think it has been tested in IE
                >
                Not your code, it's the code RobG posted that doesn't work on IE.
                >

                It doesn't use the same option twice it creates a new option based on
                the existing 1
                >
                Yes, and I'm simply saying that, contrary to what RobG said you do actually
                have to do that to get it to work on IE.
                >
                On your original point, I think you do have to set the selectedIndex to
                something, either the previous or next element in the list. I agree with
                you its annoying, but I think you will have to do it to be sure of
                consistent behaviour.

                Comment

                Working...