Drop down menu's
Using multiple drop down menu's in a form, what is the right way to get the contents on one menu to change depending on the selection of a previous menu ?
Thanks
Mika
Using multiple drop down menu's in a form, what is the right way to get the contents on one menu to change depending on the selection of a previous menu ?
Thanks
Mika
detox posted this at 13:32 — 10th February 2002.
They have: 571 posts
Joined: Feb 2001
here is a really bulky javascript way of doing it. I am sure there are others out there but I remember having this in a code library, I cant remember where i downloaded it from. Will have a look around for a better solution and if all else fails will write one myself. Anyone else know of a script?
<?php
<html>
<head>
<title></title>
<script type=\"text/javascript\">
var MyScript, MyCategory, MyItem;
MyScript = \"-= Selection.Swap.Menu.v1.0-[desYpfa] =-\";
document.title = MyScript;
window.status = MyScript;
// -=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=--=-=--=-=-=-=-MyCategory = new Array;
MyItem = new Array;
MyItem[101]=\"Item-101-(ReadMe)\";
MyItem[102]=\"Item-102-(ReadMe)\";
MyItem[211]=\"Item-211\";
MyItem[222]=\"Item-212\";
MyItem[233]=\"Item-213\";
MyItem[244]=\"Item-214\";
MyItem[255]=\"Item-215\";
MyItem[311]=MyScript;
MyItem[345]=\"\"; // Error.Fix(A) <<EXAMPLE>>
MyCategory[1]=new Array(101,102,null); // Error.Fix(B) <<EXAMPLE>>
MyCategory[2]=new Array(211,212,213,214,215);
MyCategory[3]=new Array(311,345);
function SelectSwap() {
var OptID, OptVal, i;
var SwappedCategory, SwappedItems;
SwappedCategory = document.MyForm.MyMenu1.options[document.MyForm.MyMenu1.selectedIndex].value;
SwappedItems = MyCategory[SwappedCategory].length;
for (i = 0; i < SwappedItems; i++) {
OptID = MyCategory[SwappedCategory][i];
OptVal = MyItem[OptID];
document.MyForm.MyMenu2.options[i] = new Option(OptVal, OptID);
// here is the loop that sorts thru the array.
// you must have at least 2 items or else it will error.
// to prevent the error, use the examples above (Error.Fix(A) or Error.Fix(B)) to help guide you.
}
document.MyForm.MyMenu2.length = SwappedItems;
}
// -=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=--=-=--=-=-=-=-
</script>
</head>
<body bgcolor=#ffffff>
<form name=MyForm method=post action=\"\">
<table border=0 cellpadding=5 cellspacing=0 width=\"100%\" bgcolor=#ffffff align=center>
<!-- NonSence Row --><tr valign=top><td colspan=2 bgcolor=#cfcfcf>
<div style=\"font-weight:bold;font-family:verdana;font-size:10px;color:#000000\"><script>document.write(MyScript);</script></div>
</td></tr>
<tr valign=top>
<td align=left width=150>
<select name=MyMenu1 onChange=\"SelectSwap()\" style=\"width:150px;\">
<option value=3>Select a Category</option>
<option value=1>Category-1</option>
<option value=2>Category-2</option>
<option value=3>Category-3</option>
</select>
</td>
<td align=left width=\"100%\">
<select name=MyMenu2>
<option value=0>Not Selected Yet</option>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>
?>
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.