views:

139

answers:

1

hi :)

after an hour of trying to find a solution, I give up (temporarily). "this.selectedIndex = -1" clears all select element just fine in FF and other browsers, but NOT in Internet Explorer 8.

any idea how to clear select elements in IE?

thanks!

+1  A: 

Rather than having a dropdown point to an invalid option, the standard solution is to have the first option of the dropdown say something like "(select)", so you can just reset to 0 if necessary

Michael Mrozek
Well, the `-1` value is not technically *invalid*, is [specified](http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-85676760) and expected when there are no selected elements, actually IIRC it should from IE5 up.
CMS
Interesting. I think it was intended that that be for lists with `multiple` set, since generally you can't unselect from a normal drop-down list, but you're right, it doesn't actually say that
Michael Mrozek
Also, while having a placeholder option may be the *standard solution*, it doesn't mean that it is the best. Personally, I find having no selected option when there isn't one is a better user experience. (Of course, in situations where you can't deselect all options, like in IE, then you may have to resort to the placeholder option.)
Steve Harrison
@Steve My main problem with that solution is there's no convenient way for the user to deselect an option in a single-selection dropdown
Michael Mrozek
Thanks, I'll go with the placeholder solution.
ML