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.

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.