OPTGROUP: I guess I am still not done learning new HTML tags

Posted : July 4, 2004 at 4:15 pm [America/Los_Angeles]

[via WebMaster tips]

Basically, OPTGROUP groups different OPTION tags under a common name or label. Here’s a simple example:

...
...
Your favorite book?<br>
<select name="books"> 

<optgroup label="Java Books">
<option label="Thinking in Java">Thinking in Java</option>
<option label="Core Java Programming">Core Java Programming</option>
<option label="Java sucks">Java sucks</option>
</optgroup> 

<optgroup label="Perl Books">
<option label="Perl Programming">Perl Programming</option>
<option label="Learning Perl">Learning Perl</option>
<option label="Perl Black Book">Perl Black Book</option>
<option label="Perl sucks too">Perl sucks too</option>
</optgroup>

<option>Other</option> 

</select>
...
...

The result is:

Your favorite book?

If you do not see the entries “Java Books” and Perl Books” in the drop-down list above, your browser probably does not support OPTGROUP. It seems to work well in IE 6.x and Firefox. According to the article linked above, the best part is that it degrades gracefully for browsers that do not support OPTGROUP.

- Anand

Viewed: 608 times