...

View Full Version : Resolved change selectedIndex IE bug



Jahren
06-19-2009, 08:00 PM
hi guys

Simple question :

why does this work under FF and only ONCE in IE


if(!this.checked)
document.getElementById("slcNiveaux").selectedIndex=0;



edit :

I tried :



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 !

Philip M
06-19-2009, 08:55 PM
Does this help?


<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.

Jahren
06-19-2009, 09:05 PM
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 :(

Philip M
06-19-2009, 09:11 PM
but unfortunately, IE accept it only once.


I don't really understand your problem.


<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.

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).

Jahren
06-19-2009, 09:14 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum