JavaScript Selection Lists
Posted by Daniel Lyons Tue, 17 Oct 2006 20:47:20 GMT
To remove an item from a <select> box in JavaScript, all you do is this:
form.myselect.options[i] = null;
This has the effect of removing the i‘th element from the list.
<blink>
Of course this is quite easily explained by a metaphor from life:
- You arrive at the security line at the airport.
- The aviation security monkey places three bins in front of you.
- You empty your pockets into the first bin.
- You realize you do not need the additional bins.
- You reach into your pocket and pull out a wad of nothing, and drop it into the second bin. The second bin vaporizes and the third bin slides up against the first bin, becoming the second bin in the process.
- You reach into your pocket and pull out the same wad of nothing, and drop it into the new second bin. It vaporizes and you have only one bin.
Naturally.

Wait a minute. Are you sure the first wad of nothing is the same as the second wad of nothing? Or do you have an unlimited supply of nothings in your pocket? And where did the first wad of nothing go when the second bin vanished? Does the nothing disappear along with the thing that had nothing in it?
Another great way to do this would be to set the existence property of the item to false. When I’m pushing my son on the tire swing he always phrases his request the same way:
“Underdog, no dizzy time. If dizzy time then you dot existence equals false.”
Michael, that’s excellent.
Web design stuff makes my head hurt.
Of course you could use form.myselect.remove(i); and fuggetabout null… :-)
Of course you could use form.myselect.remove(i); and fuggetabout null… :-)