Hmm, I’m trying to remove elements from a drop-down box based on the selectedIndex of another. Here’s what I’ve got so far:
[code]
function removeWrongColor(value) {
var color = document.getElementById(“colors”);
switch (value) {
case ‘red_delicious’:
color.remove(color.selectedIndex = 0);
color.remove(color.selectedIndex = 2);
color.remove(color.selectedIndex = 3);
break;
case ‘granny_smith’:
color.remove(color.selectedIndex = 0);
color.remove(color.selectedIndex = 1);
color.remove(color.selectedIndex = 2);
break;
case ‘gala’:
color.remove(color.selectedIndex = 0);
color.remove(color.selectedIndex = 1);
color.remove(color.selectedIndex = 3);
break;
}
}
…
<select id=”appleTypes” onchange=”removeWrongColor(value)”>
<option value=”none” selected=”selected”></option>
<option value=”red_delicious”>red delicious</option>
<option value=”granny_smith”>granny smith</option>
<option value=”gala”>gala</option>
</select>
<select id=”colors”>
<option value=”none” selected=”selected”></option>
<option value=”red”>red</option>
<option value=”yellow”>yellow</option>
<option value=”green”>green</option>
</select>
As I run this in my browser (FF 3.0b5/Linux) and make my selection, it doesn’t remove all of the elements that I’m expecting from the other drop-down box. The ‘error console’ also says something about an ‘uncaught exception’. Am I doing something wrong?