spacer
Yehuda Shiran July 16, 2001, revised December 6, 2002
Grouping Menu Entries
Tips: July 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

The latest browsers (Mozilla 1+, Netscape 6+, Internet Explorer 6+) support a new HTML tag: OPTGROUP. Use it to group selection alternatives in a SELECT element. Try this example:

Here is the HTML code:

<SELECT>
    <OPTGROUP  ID="ford" LABEL="Ford">
        <OPTION>Taurus</OPTION>
        <OPTION>Escort</OPTION>
        <OPTION>Focus</OPTION>
    </OPTGROUP>
    <OPTGROUP  ID="opel" LABEL="Opel">
        <OPTION>Astra</OPTION>
        <OPTION>Corsa</OPTION>
        <OPTION>Omega</OPTION>
    </OPTGROUP>        
</SELECT>

We now have two objects on this page: ford and opel. They support two properties: disabled and id. The property disabled can be set to true and then the group should be unavailable for selection in the SELECT menu. Here is how you set disabled:

<SCRIPT LANGUAGE="JavaScript">
<!--
document.getElementById('ford').disabled = true;
// -->
</SCRIPT>

Click here to disable the ford group and click here to alert it. You can view the disabled value by doing this:

<SCRIPT LANGUAGE="JavaScript">
<!--
alert(document.getElementById('ford').disabled);
// -->
</SCRIPT>

Beware of browser differences when using this new tag, however. In Netscape 6.x, groups are displayed but there is no visual difference to the user when a group is disabled. Additionally, if an item had previously been selected in a now disabled group it will still be visible as the selected option. This latter point is also true for Netscape 7 and Mozilla, though those browsers do change the color of a disabled group to indicate that it is disabled. Finally, in Internet Explorer 6 the disabled parameter does not appear to make any change to the select group; items are still visible and selectable after setting disabled to true.


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Installing and Using Meeplace, the Business Review CMS · Sending an HTML and Plain Text E-newsletter with ASP.NET, Part 2 · Create Multilingual Web Sites with Windows Unicode Fonts
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MySql View Technique for Grouping Crosstab Column Data · Why You Need a Mobile Web Site · Tame Web Marketing with Social Media Management