473,385 Members | 1,843 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,385 software developers and data experts.

updating country,city,state in drop down box

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 of data storage and datastructure can be used. ? How this can be done in php + javascript ?

Thanks in advance
somaskarthic
Aug 30 '06 #1
10 22856
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 of data storage and datastructure can be used. ? How this can be done in php + javascript ?

Thanks in advance
somaskarthic
Aug 30 '06 #2
vssp
268 100+
Hi friend using AJAX functionality Its very easy to complete ur task.
I will send sample code to later using AJAX concept to drop down select option
Aug 30 '06 #3
Thanks . Please send the AJAX code .


Hi friend using AJAX functionality Its very easy to complete ur task.
I will send sample code to later using AJAX concept to drop down select option
Aug 30 '06 #4
vssp
268 100+
Here is the ajax code this code i call one php file
This file u write your coading
Expand|Select|Wrap|Line Numbers
  1.  
  2.     if(window.XMLHttpRequest)
  3.         {
  4.             http=new XMLHttpRequest();
  5.         }
  6.         else if(window.ActiveXObject)
  7.         {
  8.             http=new ActiveXObject("Microsoft.XMLHTTP");
  9.         }
  10.  
  11.         var url = "countrylist.php?cid="+search_program.value;
  12.         //alert(url);  
  13.         //mlsaddress=address;
  14.         http.open("GET", url , true);
  15.  
  16.         http.onreadystatechange = countryprocess;
  17.  
  18.         http.send(null);
  19. //==jai            
  20.     }
  21. }
  22.  
  23. function countryprocess()
  24. {
  25.     if (http.readyState == 4) {
  26.     // Split the comma delimited response into an array
  27.         if(http.status==200)
  28.         {  alert(http.responseText);
  29.  
  30.  
  31.  
  32.             if(http.responseText!="No values")
  33.             {
  34.                 var clist=http.responseText.split("_");
  35.                 for(i=0;i<clist.length;i++)
  36.                 {
  37.                     var myclist=clist[i].split(",");
  38.                     document.getElementById("search_country").options[i+1]=new Option(myclist[1],myclist[0]);
  39.                 }
  40.             }
  41.  
  42.  
  43.         }
  44.  
  45.   }
  46. }
  47.  
Aug 30 '06 #5
Hi

My web server is Fedora Core 4 Linux. If i use window.ActiveXObjects (for Ajax) , will it work ?

Please post your reply
-somaskarthic
Aug 31 '06 #6
vssp
268 100+
Yes I hope its working My prodection serevr are linux machine Now working well

So you try to implement the code.
Aug 31 '06 #7
unicorn
23
here u go, u have to change group into whatever u want. in groups there is specified array of groups. it is very simple

---> experim.php



Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4.   <title></title>
  5. </head>
  6.  
  7. <body>
  8.  
  9. <SCRIPT language=JavaScript>
  10. function reload(form)
  11. {
  12. // Setting the variable with the value of selected country's ID
  13. var val=populate.countries.options[populate.countries.options.selectedIndex].value;
  14. self.location='experim.php?countryId=' + val;
  15. var val2=val+'&cityID='+populate.cities.options[populate.cities.options.selectedIndex].value;
  16. self.location='experim.php?countryId=' + val2;
  17. var val3=val2+'&groupID='+populate.groups.options[populate.groups.options.selectedIndex].value;
  18. self.location='experim.php?countryId=' + val3;
  19. }
  20. JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green.");
  21. </script>
  22.  
  23.  
  24. <?php
  25. function getCountryList()
  26. {  $countries     = array (
  27.                           '1' => 'Bangladesh',
  28.                           '2' => 'USA',
  29.                           '3' => 'UK'
  30.                           );
  31.  
  32.   return $countries;
  33. }
  34.  
  35.  
  36. function getCityList($countryId)
  37. {
  38.   // City list array
  39.   // First key of the array is the Country ID, which holds an array of City list
  40.   $cities       = array (
  41.                           'Bangladesh' => array ('Dhaka', 'Chittagong', 'What else'),
  42.                           'UK' => array ('London', 'Cannot Remember'),
  43.                           'USA' => array ('Washington', 'N.Y.', 'etc')
  44.                           );
  45.  
  46.   return $cities[$countryId];
  47. }
  48.  
  49.  
  50. function getGroupList($cityID)
  51. {
  52.   $groups       = array (
  53.  
  54.                           'etc' => array ('aka', 'Chg', ' else'),
  55.                           'Washington' => array ('ndon', 'Cnnot member'),
  56.                           'N.Y.' => array ('ashington', 'N.Y.', 'et')
  57.                //list of groups
  58.  
  59.                           );
  60.  
  61.  
  62.   return $groups[$cityID];
  63. }
  64.  
  65.  
  66.  
  67. ?>
  68. <form action="experim.php" name="populate">
  69. <?
  70.  
  71. // Retrieving the country list
  72. $countries  = getCountryList();
  73.  
  74. // Setting the variable if the country is selected for its city list
  75. @$countryId  = $_GET['countryId'];
  76. @$cityID = $_GET['cityID'];
  77. // Retrieving the city list if a country is selected
  78. $cities   = ($countryId) ? getCityList($countryId) : null;
  79. $groups   = ($cityID) ? getGroupList($cityID) : null;
  80.  
  81. if (!empty($countries))
  82. {
  83.   // Generating the country drop down menu
  84.   echo "<select onChange='reload(this.form)' name='countries'>";
  85.   foreach ($countries as  $value)
  86.   {
  87.     echo "<option value='$value'";
  88.  
  89.     if ($countryId == $value)
  90.       echo "selected";
  91.  
  92.     echo ">$value</option>";
  93.   }
  94.   echo "</select>";
  95. }
  96.  
  97. if (!empty($cities))
  98. {
  99.   // Generating the city drop down menu if a country is selected
  100.   echo "<select onChange='reload(this.form)' name='cities'>";
  101.   foreach ($cities as $value)
  102.   {
  103.     echo "<option value='$value'";
  104.  
  105.     if ($cityID == $value)
  106.       echo "selected";
  107.  
  108.     echo ">$value</option>";
  109.   }
  110.   echo "</select>";
  111. }
  112.  
  113.  
  114. if (!empty($groups))
  115. {
  116.   // Generating the city drop down menu if a country is selected
  117.   echo "<select onChange='reload(this.form)' name='groups'>";
  118.   foreach ($groups as $value)
  119.   {
  120.     echo "<option value='$value'";
  121.  
  122.     if ($groupID == $value)
  123.       echo "selected";
  124.  
  125.     echo ">$value</option>";
  126.   }
  127.   echo "</select>";
  128. }
  129.  
  130.  
  131.  
  132.  
  133. if (!empty($groups))
  134. {
  135.   // Generating the city drop down menu if a country is selected
  136.   echo "<select name='groups'>";
  137.   foreach ($groups as $key=>$value)
  138.   {
  139.     echo "<option value='$key'>$value</option>";
  140.   }
  141.   echo "</select>";
  142. }
  143.  
  144.  
  145. ?>
  146.  
  147. </body>
  148.  
  149. </html>
Sep 27 '06 #8
Hi friend using AJAX functionality Its very easy to complete ur task.
I will send sample code to later using AJAX concept to drop down select option
elo there, is it okay if you send also to me the complete code... just for updating country, citym state.. please.. thank you so much..
Oct 2 '06 #9
I am also facing problem in making
the country, state, city drop down selct box.
but fails

if u have any plz send me

thax
Nov 25 '11 #10
acoder
16,027 Expert Mod 8TB
Post your code attempt describing what problems you're having and I can split it off into its own thread.
Nov 25 '11 #11

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

Similar topics

1
by: B. G. Mahesh | last post by:
hi In the registration form I have city, state, country fields. I was wondering if there was a database available on the net which has the list of states in each of the countries. That way when...
1
by: zoneal | last post by:
I retrieved the following function from VB.NET help and added a few statements for updating the datasource. But, it does not actually commence the InsertCommand property of the DataAdapter in order...
4
by: steve_barker333 | last post by:
Hi guys, I'm designing a web-site that will allow users to look up other people, based on certain criteria. The most important criterion is geographical location. I've managed to find 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...
1
by: icepoint | last post by:
Hey everyone, Can anyone tell me how to make dynamice drop down lists for country and states? I have the models for country and states build and have the country drop down list worked, so how can I...
10
by: help4me | last post by:
I am having trouble updating a table. The logic seems so simple but I just can’t get it to work. The table is named test. The column names are passcode, name, address, city, state, zip and email....
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...
7
by: tokcy | last post by:
Hi everyone, I need the world database of country state and city. Actually i have three drop down option in my project in 1st drop down country name should come from database and 2nd drop down...
5
by: bennever | last post by:
Hi, I plan to use drop down lists to populate team results and will use the standard country/state drop down lists as the base code. The question: how can I populate multiple (5) states from...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.