Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2009
    Posts
    143
    Thanks
    14
    Thanked 1 Time in 1 Post

    Internet Explorer change selectedIndex IE bug

    hi guys

    Simple question :

    why does this work under FF and only ONCE in IE
    Code:
    if(!this.checked)
          document.getElementById("slcNiveaux").selectedIndex=0;

    edit :

    I tried :

    Code:
    function resetSelectIndex(chk, idSelect){
    	if(!chk.checked){
    		document.getElementById(idSelect).selectedIndex=0; //Firefox only
    		document.getElementById(idSelect).options[0].setAttribute("selected",true); //IE only
    	}
    }
    but the problem remains the same as the firefox only code crashed IE's javascript...
    so it works only once still


    Edit : SOLUTION -> changed event from onchange to onclick for my checkbox calling that function !
    Last edited by Jahren; 06-19-2009 at 08:15 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,015
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Does this help?

    Code:
    <form name='myform'>
    <select name = 'list1' id = 'list1' onchange = "rem(this)">
    <option selected value=""> Choose A Fruit</option>
    <option value='Mango'> Mango </option>
    <option value='Apple'> Apple </option>
    <option value='Orange'> Orange </option>
    </form>
    
    <script type = "text/javascript">
    function rem(which) {
    document.myform.list1.selectedIndex = 0;
    // document.getElementById("list1").selectedIndex = 0;  // alternative
    }
    
    </script>
    "That which seems the height of absurdity in one generation often becomes the height of wisdom in the next". - John Stuart Mill.

  • #3
    Regular Coder
    Join Date
    May 2009
    Posts
    143
    Thanks
    14
    Thanked 1 Time in 1 Post
    thanks for the help

    but unfortunately, IE accept it only once.
    same as my solution above.

    I know some people are having this issue, But no one got an answer yet

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,015
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by Jahren View Post
    but unfortunately, IE accept it only once.
    I don't really understand your problem.

    Code:
    <form name='myform'>
    <select name = 'list1' id = 'list1' onchange = "rem(this)">
    <option selected value=""> Choose A Fruit</option>
    <option value='Mango'> Mango </option>
    <option value='Apple'> Apple </option>
    <option value='Orange'> Orange </option>
    </form>
    
    <script type = "text/javascript">
    var count = 0;
    function rem(which) {
    document.myform.list1.selectedIndex = count;
    count ++;
    }
    
    </script>
    behaves as you would expect.

    Edit: It seems that the problem was caused by using onchange instead of onclick to trigger the function.
    Internet Explorer only fires the onchange event when the checkbox loses the focus (onblur).
    Last edited by Philip M; 06-19-2009 at 08:17 PM.

  • Users who have thanked Philip M for this post:

    Jahren (06-19-2009)

  • #5
    Regular Coder
    Join Date
    May 2009
    Posts
    143
    Thanks
    14
    Thanked 1 Time in 1 Post
    as stated in the other topic, changing my checkboxes' event from onchange to onclick solved my problem!

    My code was really running only once in IE lol
    After that one time, it wouldn't fire the event anymore


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •