Click to See Complete Forum and Search --> : Linking menus


NowhereMan97
07-29-2003, 03:53 PM
Okay, so I have two drop-down menus on a form. One lists employees and one lists Workgroups. These lists come from two tables that are connected through a GroupID field (each employee has a GroupID that corresponds with the Groups table).

Right now when I fill a form I have to select an employee and then select their group.

Is there a way to link the drop-down menus so that when you select an employee it will automatically select his group in the group drop-down menu?

Any help would be appreciated.

Thanks!

pyro
07-29-2003, 04:03 PM
Something like this, perhaps?

<script type="text/javascript">
function setVals(sel) {
who = sel.options[sel.selectedIndex].value;
if (who == "Compguy Pete") {
document.myform.group.selectedIndex = 0;
}
else if (who == "pyro" || who == "Khalid Ali" || who == "Dave Clark") {
document.myform.group.selectedIndex = 1;
}
else {
document.myform.group.selectedIndex = 2;
}
}
</script>
</head>
<body>
<form name="myform">
<select name="employee" onchange="setVals(this);">
<option value="Compguy Pete">Compguy Pete</option>
<option value="pyro">pyro</option>
<option value="Khalid Ali">Khalid Ali</option>
<option value="DaveSW">DaveSW</option>
<option value="Jeff Mott">Jeff Mott</option>
<option value="Dave Clark">Dave Clark</option>
</select>
<select name="group">
<option value="administrator">Administrator</option>
<option value="supermoderator">Super Moderator</option>
<option value="moderator">Moderator</option>
</select>
</form>

NowhereMan97
07-29-2003, 04:16 PM
Yes almost there, very close.

Is there a way to make it a little more dynamic because the dropdown lists come from a database.

pyro
07-29-2003, 04:50 PM
If this works for you, it would be a much easier way of doing it:

<script type="text/javascript">
function setVals(sel) {
document.myform.group.selectedIndex = sel.options[sel.selectedIndex].value;
}
</script>
</head>
<body>
<form name="myform">
<select name="employee" onchange="setVals(this);">
<option value="0">Compguy Pete</option>
<option value="1">pyro</option>
<option value="1">Khalid Ali</option>
<option value="2">DaveSW</option>
<option value="2">Jeff Mott</option>
<option value="1">Dave Clark</option>
</select>
<select name="group">
<option value="administrator">Administrator</option>
<option value="supermoderator">Super Moderator</option>
<option value="moderator">Moderator</option>
</select>
</form>

NowhereMan97
07-29-2003, 05:07 PM
Very cool!

Here is the catch - I already have a value for the employees that I want to leave as is - so is there a way pick a group by maybe sending the group value through the onchange command?

pyro
07-29-2003, 05:10 PM
How 'bouts this? ;)

<script type="text/javascript">
function setVals(sel) {
document.myform.group.selectedIndex = sel.options[sel.selectedIndex].name;
}
</script>
</head>
<body>
<form name="myform">
<select name="employee" onchange="setVals(this);">
<option value="Compguy Pete" name="0">Compguy Pete</option>
<option value="pyro" name="1">pyro</option>
<option value="Khalid Ali" name="1">Khalid Ali</option>
<option value="DaveSW" name="2">DaveSW</option>
<option value="Jeff Mott" name="2">Jeff Mott</option>
<option value="Dave Clark" name="1">Dave Clark</option>
</select>
<select name="group">
<option value="administrator">Administrator</option>
<option value="supermoderator">Super Moderator</option>
<option value="moderator">Moderator</option>
</select>
</form>

NowhereMan97
07-29-2003, 06:19 PM
Dude, you are da man! :D

pyro
07-29-2003, 10:59 PM
Thanks... :D Glad to be able to help you out.