Click to See Complete Forum and Search --> : multiple combo selection message
aamirc
07-14-2003, 12:55 AM
i have 11 combo boxes which contain around 50 to 70 names of people. These names are retrieved from the database. Each combo box contains all of the names. The user should not be allowed to select the same name in more than one combo box. Upon selecting the same name an alert should be displayed. Anyone can tell me how its done? i am new to javascript.
Gollum
07-14-2003, 02:17 AM
With your combos in a form, make them all the same name so you can access them in an array...
<html>
<head>
<script>
function CheckNames(oSel)
{
var aSel = document.theForm.theNames;
var i, n = aSel.length;
for ( i = 0; i < n; i++ )
{
if ( (aSel[i] != oSel) && (aSel[i].value == oSel.value) && (aSel[i].value > 0) )
{
alert('No two names may be alike');
oSel.selectedIndex = 0;
oSel.focus();
}
}
}
</script>
</head>
<body>
<form name=theForm>
<select name=theNames onclick="CheckNames(this);">
<option value=0>Select A Name
<option value=1>Tom
<option value=2>Dick
<option value=3>Harry
<option value=4>Hewie
<option value=5>Dewey
<option value=6>Louie
</select>
<select name=theNames onclick="CheckNames(this);">
<option value=0>Select A Name
<option value=1>Tom
<option value=2>Dick
<option value=3>Harry
<option value=4>Hewie
<option value=5>Dewey
<option value=6>Louie
</select>
<select name=theNames onclick="CheckNames(this);">
<option value=0>Select A Name
<option value=1>Tom
<option value=2>Dick
<option value=3>Harry
<option value=4>Hewie
<option value=5>Dewey
<option value=6>Louie
</select>
</form>
</body>
</html>
aamirc
07-14-2003, 03:33 AM
thanx a million! :)