0

Please help me.I'll really thank for you help! How to write code for country, state and city drop down list menu? change automatically for state and city when country is selected.

Edited by Wailintun: add more

2
Contributors
1
Reply
6
Views
4 Years
Discussion Span
Last Post by diafol
0

This is relatively trivial and can be done easily with some javascript. However the ease of implementing this will depend very much on how your data is stored and whether you need a round trip to the server on every change in selection. Personally, I'd dump the data into a json format on page load - so no need to use ajax or anything else.

I'm assuming that your data is normalized and stored in a DB.

Hmm, re-reading the post, you say 'country' - that seems like a heck of a lot of data stored for state and city. The following is assuming every city MUST have a state:

COUNTRIES

FIELD          TYPE             
-------------  ---------------- 
country_id     TINYINT(3) UNSIGNED 
country_code   VARCHAR(10)      
country_label  VARCHAR(20)           

STATES

FIELD        TYPE              
-----------  ----------------  
state_id     INT(5) UNSIGNED  
state_code   VARCHAR(5)        
state_label  VARCHAR(30)       
country_id   TINYINT(3)           

CITIES

FIELD       TYPE              
----------  ----------------  
city_id     INT(5) UNSIGNED  
city_label  VARCHAR(20)       
state_id    INT(5)

The _code fields are optional.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.