Dave's Brain

Browse - Programming Tips - How can I show/hide a select's options ?

Date: 2010sep2
Language: javaScript

Q.  How can I show/hide a <select>'s <option>s ?

A.  With Firefox you can do:

for (i = 0; i < objSelect.options.length; i++) { if (isWantIt(objSelect.options[i].value)) { objSelect.options[i].style.display = 'block'; } else { objSelect.options[i].style.display = 'none'; } }
But sadly, that doesn't work in IE. Changing the className doesn't work either. With IE you have to change all the options!

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.