[web] Creating a dependent drop down menu

Started by
2 comments, last by Mathachew 17 years, 8 months ago
Im using PHP to connect to a sql database, and im wanting to create a dependent select option that will automatically refresh, then populate a second select option based on the selection chosen initially. Example: User selects their country from drop down menu A, page automatically refreshes, then drop down menu b is automatically populated with the cities from the country selected. Any ideas, im wanting to keep everything done server side were possible.
Advertisement
-if you are ok with refreshing the full page, juste use the &#106avascript method "onChange" of the dowpdown input, ie. onChange="myForm.submit();"
then populate the second dropdown when you refresh the page. Be careful, you also have to "refill" any other field already entered.
-if you don't want to refresh the full page, use Ajax technology, but it far more complex.
Yeah thats great, I dont mind refreshing the whole page as the drop down menu is initially the only option that is available.

Cheers :)
There are a lot of examples of this.

Chained selections:
http://dynamicdrive.com/dynamicindex16/chainedselects/index.htm
It doesn't sound like this is exactly what you're looking for, but it could give you some insight on what's possible.

A co-worker had an idea on making our Dealer's page a little more compact, and not the flooded google map that it currently is:
http://www.computrols.com/map_test.php

The downer to my script is that everything is generated (the HTML already exists and isn't really dynamic). All that's occurring is the select menu's being hidden and one being shown. There are several ways this can be done. I quickly whipped it together to show our Customer Service the idea. Ignore anything else unrelated to the JS that works with the select options; I hold no claim to it since I didn't make it ;)

You can also use AJAX, which can make this a little more complicated if you haven't messed with it before. Let me know if you need some help. Something like this is relatively easy.

This topic is closed to new replies.

Advertisement