How do you go about creating two dropdown boxes such that when you select a value from the first one, the second is populated with values that depend on the first? Well here's an example.
The example form is coded as follows:
All that you need to do to get this function to populate the second dropdown box with your desired values for each of the values in your first dropdown box is to repeat the if statement checking which entry was chosen for all of the different values that can be selected in your first dropdown box. Within each of these you have one selbox.options assignment statement for each value that you want to appear in the second dropdown box (I have included two options in each built you can have as many as you like). The first entry in the option field on the right is the literal that you want to appear as a selectable value in the dropdown box and the second entry is the value that you want to assign to the particular selection.
I have included a button at the end of the form that when clicked will display the value assigned by the second dropdown box just so you can see which value it is set to with the various combinations of selections in the two dropdown boxes. You don't need to include the button in your form but the code does show you how to test the value of the second dropdown box.
You can call your form whatever you want, just substitute its name wherever you see myform in the above example. Similarly you can change the names of the first and second dropdown boxes to whatever you like by substituting for optone and opttwo everywhere they appear.
Note that this page is copied from the "Ask Felgall" website with the permission of the copyright owner.
It is of course reasonably easy to modify this code to handle three or more linked dropdowns.