[thelist] Deselecting a select element in JS
.jeff
jeff at members.evolt.org
Thu Mar 21 13:24:00 CST 2002
andrew,
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Hardacker, Andrew
>
> > How do you deselect a select element using JavaScript
> > (IYSWIM) ?
>
> I don't believe you can. IE will let you set
> selectedIndex to a negative number, but that's
> technically illegal - it has to be positive -
> so Netscape will override any attempt to set
> selectedIndex to -1 or null with 0, which corresponds
> to the first option.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
where do you see that it says that a negative number is invalid? here's an exercise for you. make a page with a select with no options selected. now, pop an alert() to get the selectedIndex of that select. guess what, it's -1. if you can read a -1, you can probably set a -1.
just to be absolutely sure, i put this example together:
http://members.evolt.org/jeff/code/select_reset.cfm
enjoy,
.jeff
http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/
More information about the thelist
mailing list