Hiding OPTIONS in SELECT ?

  • Thread starter comp.lang.javascript
  • Start date
C

comp.lang.javascript

Using IE5.5+, is it possible to hide options in a select?

The following doesn't work:

<HTML>
<HEAD>
<STYLE>
SELECT OPTION.orgA{ display:none }
.orgB{ display:inline }
.orgC{ display:none }
</STYLE>
</HEAD>
<BODY>
<SELECT id=cbo size=3>
<OPTION class="orgA">RTI</OPTION>
<OPTION class="orgB">LAB</OPTION>
<OPTION class="orgC">TCI</OPTION>
</SELECT>
</BODY>
</HTML>



Best Regards,
Jesse Wade


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
G

Grant Wagner

comp.lang.javascript said:
Using IE5.5+, is it possible to hide options in a select?

The following doesn't work:

<HTML>
<HEAD>
<STYLE>
SELECT OPTION.orgA{ display:none }
.orgB{ display:inline }
.orgC{ display:none }
</STYLE>
</HEAD>
<BODY>
<SELECT id=cbo size=3>
<OPTION class="orgA">RTI</OPTION>
<OPTION class="orgB">LAB</OPTION>
<OPTION class="orgC">TCI</OPTION>
</SELECT>
</BODY>
</HTML>

Best Regards,
Jesse Wade

If you want to have items dynamically appear and disappear from a
<select> you're going to have to remove the references to the
actual <option> objects and recreate them when you want them
"visible":

document.getElementById{'cbo').options[1] = null;


var select = document.getElementById('cbo');
select.options[select.option.length] = new Option(...);

Of course that adds it to the bottom, if you want it added at the
cursor position or in sorted order, you'll have to re-order the
<option> objects after you add the new ones.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available
at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top