I have an option box with 30 items in 5 groups. To make it easier for the user, I put in a title before each of the groups. This is done in a php function.
When a user clicks on an item I get the correct name but the wrong selectedIndex because of the titles.
I set up a global variable called $deduct and set the value to which group it is in. I can then adjust the selectedIndex by the value of $deduct.
Is there a way to do this?
use optgroups to separate option groups-
the optgroup elements are not counted in the options array
<select name="select_1" size="1">
<option selected="selected" value="0">Select element</option>
<option value="1"> Option 1</option>
<optgroup label="First optgroup">
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<optgroup label="Second optgroup">
<option value="5">Option 5</option>
<option value="6">Option 6</option>
<option value="7">Option 7</option>
Last edited by mrhoo; 04-14-2010 at 02:11 PM.
just to expand on this:
Originally Posted by mrhoo
you can determine the group by looking at the selcted option, and giving the group a memo class:
<optgroup class="grp1" label="First optgroup">
//demo select onchange:
var si=this.selectedIndex, ops=this.options, op=ops[si], mom=op.parentNode.className; alert( "Text: "+ op.text+"\nParent"+mom )
Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)