Selecting State in first dropdown menu and then relevent City in the next

I have searched for the answer through Google and I’m not even sure I have searched for the proper terms.

Here is the problem: I have two dropdown menus populated with data from the MYSQL database. The first is the State menu. You click it and all the states in the database dropdown and you choose the proper State. The second dropdown menu is for City and as with the State menu, you click on it, and all the cities in the database dropdown. As you might guess there are a lot of cities. So, I’d like to have it so that only the cities that are in the State I chose will show in the second drop down menu. I know how to do this if I go from one page to another using $variables but I’d like it to happen all on the same page. I’m thinking it may require more than PHP. Any help would be greatly appreciated. A link in the right direction is all I’m asking for.

Thanks
Steve

Without a doubt you’ll need to use JavaScript to make that happen in the same page, without page reload. This kind of problem is very common so I’m sure you can find more examples on Google.

Example: http://jsfiddle.net/mplungjan/65Q9L/

If you’re not familiar with JavaScript it could be a little bit hard to think and come up with a great solution so you can always use some kind of JavaScript plugin for this purpose, when selection list depends on other selection value it’s basically called chainable dropdown list.

If still you can’t find your way about this issue, let me know.

There’s a topic on here talking about issues with a submenu, only a week or so back, I posted some sample code that calls a short PHP script on selection of a first menu item, to recover data and populate the sub-menu.

Found it: How to auto-fill 2 drop-down and text-box based upon on the first drop-down value selected? - #7 by droopsnoot

Thanks for the help, DroopSnoot. It is a appreciated. The purpose of my inquiry is to build (as you may have guessed) a website that uses the easiest possible route for a user to pick their area. Well, I figured I would look into zip codes and I found a great database on sourceforge and a script from another site that will bring a user straight to their area. However, I have been having problems with importing the .CSV file into MySql using phpmyadmin. I’ll figure it out, eventually. Or, if anyone knows of a file out there that will import with little to no problems I would love to see it.

Again, thank you for the help.
Steve

Thanks
Steve

Glad it might help. As for the importing problems, I guess it depends on specifically what the problems are. Usually the biggest issue with importing CSV files is when the data contains commas inside a single column, requiring that column to either be surrounded by quotes, or using tab characters to separate instead of commas.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.