473,324 Members | 2,548 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,324 software developers and data experts.

about country,state,city selection

1
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 ?plzz reply guys if anyone knws it
Feb 9 '07 #1
5 9360
Motoma
3,237 Expert 2GB
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 ?plzz reply guys if anyone knws it
PHP will initially populate the dropdown boxes. You will then need javascript to perform the switching and swapping after the page has loaded.
A good thing to note, PHP is executed on a Server, before the page has loaded on the client's web browser, Javascript is executed in the web browser, after the page has been served. Without some snazzy programming, there is very little interaction between the two.
Feb 9 '07 #2
Motoma
3,237 Expert 2GB
I have moved this thread to the Javascript forum, as I feel that the kids there will be able to help you out much better.
Feb 9 '07 #3
abctech
157 100+
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 ?plzz reply guys if anyone knws it
Hi,
I don't know PHP, but have a look at the fol. code which is in JS :-
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="javascript">
  4. function showField()
  5. {
  6. var choice = document.formname.drop1.options[document.formname.drop1.selectedIndex].value;
  7.  
  8. if(choice == "US")
  9. {
  10. document.all['other-div'].style.display = "none";
  11. document.all['US-div'].style.display = "";
  12. }
  13.  
  14. else if(choice == "other")
  15. {
  16. document.all['other-div'].style.display = "";
  17. document.all['US-div'].style.display = "none";
  18. }
  19.  
  20. else
  21. {
  22. document.all['other-div'].style.display = "none";
  23. document.all['US-div'].style.display = "none";
  24. }
  25. }
  26. </script>
  27. </head>
  28. <body>
  29.  
  30. <form name="formname">
  31. <select name="drop1" onchange="showField()">
  32. <option value="pleasechoose" selected>- Please Choose -
  33. <option value="US">US
  34. <option value="other">Other
  35. </select>
  36.  
  37. <br><br>
  38.  
  39. <div style="position: absolute; display: none" name="US-div" id="US-div">
  40. <select name="US-states">
  41. <option>Option 1
  42. <option>Option 2
  43. <option>Etc...
  44. </select>
  45. </div>
  46.  
  47. <div style="position: absolute; display: none" name="other-div" id="other-div">
  48. <input type="text" name="textbox">
  49. </div>
  50.  
  51. </form>
  52.  
  53. </body>
  54. </html>
Feb 10 '07 #4
@abctech
Hi... I love your code... but... If I need it with a 3th dorp dow for cities.... Country--->State-->City....

How I get it?
Feb 17 '09 #5
acoder
16,027 Expert Mod 8TB
Unfortunately, the code posted by abctech is incorrect. The main problem is the use of document.all which is supported by a select few browsers. Give each element an ID and use document.getElementById() instead.

The code only shows and hides divs. If you want to populate drop-downs, you need to either use the add() method or add a new option via the options[] array.

To add another level for cities, just follow the same procedure: onchange call a function which populates the third drop-down depending on the selection in the second one.
Feb 18 '09 #6

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

Similar topics

1
by: jonny | last post by:
Where can I find a dbase for index.PHP Country|State|Province|CITY bjve@bjve.com
0
by: Tim Marshall | last post by:
HI folks, I'm doing an app that requires the user to be able to choose a country, then a state/province/territory, then a city and possibly somewhere in-between, some kind of region, perhaps...
2
by: Kevin | last post by:
Hi all, Does anyone know of a script or package that will allow me to calculate the localtime given a country code (and optional state/province for US/Canada)? It should factor in daylight...
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...
1
by: sahilansari | last post by:
I have a table in MYSQL database... With Country & it's corresponding States. Say i select US from the dropdown option it should automatically show all the states in US from a database file. ...
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.