473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

how to display country,state,city in drop down (without database)

hi friends,

i need some help for my project.when i select the country in drop down menu automatically display the state and city.
give some idea

Thanks
Aug 6 '14 #1
4 7240
Dormilich
8,658 Expert Mod 8TB
where do you save the country-state-city relations?
Aug 7 '14 #2
Exequiel
288 256MB
you can use array for countries, states and cities, but i suggest its better to code it in javascript, try this code. :)
Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Zick Sample</title>
  7. <script type="text/javascript">
  8.  
  9. // State lists
  10. var states = new Array();
  11.  
  12. states['Canada'] = new Array('Alberta','British Columbia','Ontario');
  13. states['Philippines'] = new Array('Manila','Albay','Cam-Sur');
  14. states['United States'] = new Array('California','Florida','New York');
  15.  
  16.  
  17. // City lists
  18. var cities = new Array();
  19.  
  20. cities['Canada'] = new Array();
  21. cities['Canada']['Alberta']          = new Array('Edmonton','Calgary');
  22. cities['Canada']['British Columbia'] = new Array('Victoria','Vancouver');
  23. cities['Canada']['Ontario']          = new Array('Toronto','Hamilton');
  24.  
  25. cities['Philippines'] = new Array();
  26. cities['Philippines']['Manila'] = new Array('Paranaque','Quezon City');
  27. cities['Philippines']['Albay']       = new Array('Legazpi City','Camalig');
  28. cities['Philippines']['Cam-Sur']         = new Array('Naga','ehem');
  29.  
  30. cities['United States'] = new Array();
  31. cities['United States']['California'] = new Array('Los Angeles','San Francisco');
  32. cities['United States']['Florida']    = new Array('Miami','Orlando');
  33. cities['United States']['New York']   = new Array('Buffalo','new York');
  34.  
  35.  
  36. function setStates() {
  37.   cntrySel = document.getElementById('country');
  38.   stateList = states[cntrySel.value];
  39.   changeSelect('state', stateList, stateList);
  40.   setCities();
  41. }
  42.  
  43. function setCities() {
  44.   cntrySel = document.getElementById('country');
  45.   stateSel = document.getElementById('state');
  46.   cityList = cities[cntrySel.value][stateSel.value];
  47.   changeSelect('city', cityList, cityList);
  48. }
  49.  
  50. function changeSelect(fieldID, newOptions, newValues) {
  51.   selectField = document.getElementById(fieldID);
  52.   selectField.options.length = 0;
  53.   for (i=0; i<newOptions.length; i++) {
  54.     selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]);
  55.   }
  56. }
  57.  
  58. function addLoadEvent(func) {
  59.   var oldonload = window.onload;
  60.   if (typeof window.onload != 'function') {
  61.     window.onload = func;
  62.   } else {
  63.     window.onload = function() {
  64.       if (oldonload) {
  65.         oldonload();
  66.       }
  67.       func();
  68.     }
  69.   }
  70. }
  71.  
  72. addLoadEvent(function() {
  73.   setStates();
  74. });
  75. </script>
  76.  
  77. </head>
  78.  
  79. <body>
  80.  
  81.      <form>
  82.         <table>
  83.         <tr>
  84.         <td style="text-align: left;">Country:</td>
  85.         <td style="text-align: left;">
  86.             <select name="country" id="country" onchange="setStates();">
  87.             <option value="Philippines">Philippines</option>
  88.               <option value="Canada">Canada</option>
  89.               <option value="United States">United States</option>
  90.             </select>
  91.         </td>
  92.         </tr><tr>
  93.         <td style="text-align: left;">State:</td>
  94.         <td style="text-align: left;">
  95.             <select name="state" id="state" onchange="setCities();">
  96.               <option value="">Please select a Country</option>
  97.             </select>
  98.         </td>
  99.         </tr><tr>
  100.         <td style="text-align: left;">City:</td>
  101.         <td style="text-align: left;">
  102.             <select name="city"  id="city">
  103.               <option value="">Please select a Country</option>
  104.             </select>
  105.         </td>
  106.         </tr>
  107.         </table>
  108.     </form>
  109.  
  110.  
  111.  
  112. </body>
  113. </html>
  114.  
  115.  
  116.  
Aug 8 '14 #3
I guess you need database to store the cities data. Geodatasource .com has it but it is not free. You may want to get the data from geonames.
Sep 4 '14 #4
Hard code mapping of country, state and city in your code, see above javascript example.
Sep 10 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: gk | last post by:
i want to have 2 dpendent drown box. one for country , and the other for city. if you change country in box1 , the city list will also change in box2.. How to do it in javascript ? can...
10
by: somaskarthic | last post by:
Hi In my php page , there is a user registration form. Here the user has to select the country, state, city from the drop down box. How this can be handled in php? If a country is selected in a...
5
by: jakas | last post by:
Hi In my php page , there is a user registration form. Here the user has to select the country, state, city from the drop down box. How this can be handled in php? If a country is selected in a...
11
by: pinocchio123 | last post by:
hi friends... in my php page 3 dropdownlist boxes are there.. ie country,state,city.. if country is selected, in onchange function.. corresponding states has to be populated in state...
1
by: patrioticcow | last post by:
hello. i have 3 tables "city" containing id, city, state_id and "states" containing id, states and "table" containing a city field (INT 11) what i want to do is to select a state then select a...
2
by: dinesh1985singh | last post by:
How do I get the country, state, city, zip code and timezone in PHP from the IP address? I searched it out on google and got lots of link but mostally links I got were paid one, I am searching for...
1
by: parimalareddy | last post by:
Hi In my php page , there is a user registration form. Here the user has to select the country, state, city from the drop down box. How this can be handled in php? If a country is selected in a...
1
by: ranjith kumar | last post by:
i had created table for countries(only 2), i had created state tables for that countries.i need to diaplay a drop down of states on selecting a country in ajax
1
by: princebhea | last post by:
How to create a dependent dropdown ,country ,state,city pls send me,suppose ,i click the country it will disply the all country list,when i select the india it will disply the all state list of india...
3
by: sunilwije | last post by:
Problem of indexing Country, State , City table. Instead of entering repeated user location for several users who share the same location I am planning to normalize by giving locationID from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.