Hide Options from Multiple Selection Box

Reddy picture Reddy · Aug 2, 2012 · Viewed 9.5k times · Source

I need to hide certain options from Multiple selection box using Javascript. I can't got for jQuery, and I am not allowed to.

I have one more dropdown box, I am calling a js function which will be called upon change of the value. The js function will control the options of another multiple select options box, where I need to hide (not remove) options based on dropdown box value.

Any simple js function?

http://jsfiddle.net/zz3dg/

Edit: tried

fastInternet.options[i].style.display = 'none';
fastInternet.options[i].style.visibility = 'hidden';

Didn't work :(

Answer

Ahsan Khurshid picture Ahsan Khurshid · Aug 2, 2012

EDITED:

New Suggestion:

What about to make it disable

fastInternet.options[i].setAttribute("disabled", "disabled")

And then hide it by using following CSS:

select option[disabled] {
    display: none; /* worked in firefox*/
    visibility: hidden; /* worked in chrome*/
}

SEE DEMO

It might help!

OLD Suggestion:

Try to use

 fastInternet.remove(options[i])