Dave's Brain

Browse - programming tips - javascript hide select option

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!
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: