IE Select Option Bug – Selected, SelectedIndex

In case anyone else is coming across this issue, for some reason, when attempting to select all options in a multi-select “<select>” box, for some reason, IE doesn’t work the first time through my iteration. Here is more:

IE Select Bug

WORKAROUND

Don’t set Multiple immediately before selecting options

Alright, I found it – for some reason, when you use javascript to set the “multiple=true”, you cannot then immediately set selected=’true’. It just doesn’t work in Internet Explorer. (Or at least we couldn’t get it to work – please let us know if you find another solution).

The Old Function

function selectAll(selector){
if(!selector)alert('Selector doesnt exist');
else{
selector.multiple=true;
for(var i=0;i
selector.options[i].selected = true;
}
return false;
}
}

The New

function selectAll(selector){
if(!selector)alert('Selector doesnt exist');
else{
/**selector.multiple=true; Call this far in advance, or have it already set to "multiple"**/
for(var i=0;i
selector.options[i].selected = true;
}
return false;
}
}


2 Responses to “IE Select Option Bug – Selected, SelectedIndex”

  • Mauricio Farias Says:

    29. Thank you for the information you have shared to us. 1 thing my sister fined this article very significant and it truly helps her in so many methods particularly dealing with her job.

  • Tison Says:

    Mauricio,

    You’re welcome I’m glad this article regarding Internet Explorer’s handling of select boxes is able to help your sister in her career.

Leave a Reply