473,672 Members | 2,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 7424
Dormilich
8,658 Recognized Expert Moderator Expert
where do you save the country-state-city relations?
Aug 7 '14 #2
Exequiel
288 Contributor
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
canelle
3 New Member
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
mukherjee
9 New Member
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
2600
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 you provide an example with few dumy country name and their cities.
10
22933
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 drop down box , its corresponding states should be populated in the state drop down box. If a state is selected , its corresponding cities should be populated in the city drop down box. Where all these data has to be stored and retrieved. What...
5
9408
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 drop down box , its corresponding states should be populated in the state drop down box. If a state is selected , its corresponding cities should be populated in the city drop down box. Where all these data has to be stored and retrieved. What type...
11
17985
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 dropdownlist box.. likewise if particular state is selected corresponding city has to be populated in 3rd list box.. can u help me?? thank you...
1
3126
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 city based on the "state_id" and the result to be stored into the "city" field inside the "table" table. the code will look like this: $city = isset($_REQUEST) ? addslashes($_REQUEST) : 0; $state = isset($_REQUEST) ? addslashes($_REQUEST) :...
2
5339
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 free one links whose accuracy would be best.
1
3390
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 drop down box , its corresponding states should be populated in the state drop down box. If a state is selected , its corresponding cities should be populated in the city drop down box. Where all these data has to be stored and retrieved. What type...
1
1522
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
2757
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 .when i select any state,it will disply the that state citys only
3
1938
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 Locations table to each user in the User table so that I don’t have to enter Country, State, City repeatedly in the User table so I save disk space. (USA, CT, Woodhaven ) After several users say 12th users may enter USA,NY, Albany and this...
0
8953
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8854
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8652
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8704
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6264
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2849
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2104
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.