Grouping Menu Items
Still another means of bringing added clarity to your forms is grouping items within a menu. This is done using the optgroup element. Along with optgroup, you also use the label attribute in both the optgroup opening tag and each individual item within that group (see Example 5-15).
Example 5-15. Using optgroup to group options in a form menu
<select name="regions" size="14"><optgroup label="Western Region"><option value="Arizona" label="Arizona">Arizona</option><option value="California" label="California">California</option><option value="Colorado" label="Colorado">Colorado</option><option value="Nevada" label="Nevada">Nevada</option><option value="Texas" label="Texas">Texas</option><option value="Utah" label="Utah">Utah</option> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access