473,405 Members | 2,373 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.

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 9365
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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,...

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.