• Advertisement
Sign in to follow this  

[web] Creating a dependent drop down menu

This topic is 4226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
-if you are ok with refreshing the full page, juste use the javascript 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.

Share this post


Link to post
Share on other sites
Yeah thats great, I dont mind refreshing the whole page as the drop down menu is initially the only option that is available.

Cheers :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement