Michael_O
asked on
n level Combo Box
I need to build at least 3 level combobox,
I mean that the combo options be divided in 3 levele for example:
Level 1
Level2
Option1
Level 1
Level2
Option1
I mean that the combo options be divided in 3 levele for example:
Level 1
Level2
Option1
Level 1
Level2
Option1
ASKER
Thank you for prompt reply. But I want it to be like Optgroup, it means that use can only choose the last level option. the two other levels are only for grouping.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Now I'm worried that it might be onselect. Pretty sure it's onchange, but I have self-doubt now...
<script language="javascript">
function validateHandler();
{
var objForm = document.forms.thisform;
if( objForm.somefield.value == 'x' )
{
alert('You must select an option from the drop down list');
objForm.somefield.focus();
return false;
} else {
return true;
}
}
</script>
<form name="thisform" onsubmit="validateHandler(
<select name="somefield">
<option value="x">Level 1</option>
<option value="x"> Level 2</option>
<option value="1"> Option 1</option>
<option value="x">Level 1</option>
<option value="x"> Level 2</option>
<option value="2"> Option 2</option>
</select>
<input type="submit">
</form>
Essentialy the technique is to use a 'dummy' value for the non-selectable options in the box, and use white space to indent the levels. Then you use the form's onsubmit event to check whether the user has selected a valid item in the drop down list. If they have, you return true from the handler and the submission proceeds. If they haven't you provide an error message, and return false, cancelling the form submit. You can also validate other things on the form while you are at it.