let's say that i have a table with all the citys and states like
id zip_code city county state_name state_prefix area_code time_zone lat lon
40001 0 All All A N/A N/A 0 0
15366 35077 Hanceville Cullman Alabama AL 256 Central 34.0643 -86.7585
15351 35055 Cullman Cullman Alabama AL 256 Central 34.174 -86.8437
15350 35054 Cropwell Saint Clair Alabama AL 205 Central 33.507 -86.2945
15349 35053 Crane Hill Cullman Alabama AL 256 Central 34.0716 -87.0597
15348 35052 Cook Springs Saint Clair Alabama AL 205 Central 33.5911 -86.3912
15347 35051 Columbiana Shelby Alabama AL 205 Central 33.1823 -86.605
15346 35049 Cleveland Blount Alabama AL 205 Central 33.9692 -86.5984
15345 35048 Clay Jefferson Alabama AL 205 Central 33.7357 -86.5702
15344 35046 Clanton Chilton Alabama AL 205 Central 32.8394 -86.6235
15343 35045 Clanton Chilton Alabama AL 205 Central 32.8392 -86.6309
15342 35044 Childersburg Talladega Alabama AL 256 Central 33.2766 -86.3523
how can i make 2 combo box for states and cities changing the city value according to the state combo box value
dynamic menu from the database
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: dynamic menu from the database
Search for something like "javascript chained combobox" and you will find many examples. Here is a jQuery one: http://jsfiddle.net/FJFFJ/1/
(#10850)
Re: dynamic menu from the database
This is often referred to as "cascading comboboxes" too, so if you want more references, try that.
I see some potential problems with your data model, though. Columns like Area Code and Latitude/Longitude are not appropriate in a table of cities, because there are frequently several area codes in large cities and there will always be an infinite number of Lat/Long pairs in a city. Since a relational database should never have have columns that contain multiple values, such as several area codes, because you can't perform efficient queries on those columns, you would need a one-to-many table for the area codes. I don't know what you might want to do about the Lat/Long values.
I see some potential problems with your data model, though. Columns like Area Code and Latitude/Longitude are not appropriate in a table of cities, because there are frequently several area codes in large cities and there will always be an infinite number of Lat/Long pairs in a city. Since a relational database should never have have columns that contain multiple values, such as several area codes, because you can't perform efficient queries on those columns, you would need a one-to-many table for the area codes. I don't know what you might want to do about the Lat/Long values.