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
4 7424 Dormilich 8,658
Recognized Expert Moderator Expert
where do you save the country-state-city relations?
you can use array for countries, states and cities, but i suggest its better to code it in javascript, try this code. :) -
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
<title>Zick Sample</title>
-
<script type="text/javascript">
-
-
// State lists
-
var states = new Array();
-
-
states['Canada'] = new Array('Alberta','British Columbia','Ontario');
-
states['Philippines'] = new Array('Manila','Albay','Cam-Sur');
-
states['United States'] = new Array('California','Florida','New York');
-
-
-
// City lists
-
var cities = new Array();
-
-
cities['Canada'] = new Array();
-
cities['Canada']['Alberta'] = new Array('Edmonton','Calgary');
-
cities['Canada']['British Columbia'] = new Array('Victoria','Vancouver');
-
cities['Canada']['Ontario'] = new Array('Toronto','Hamilton');
-
-
cities['Philippines'] = new Array();
-
cities['Philippines']['Manila'] = new Array('Paranaque','Quezon City');
-
cities['Philippines']['Albay'] = new Array('Legazpi City','Camalig');
-
cities['Philippines']['Cam-Sur'] = new Array('Naga','ehem');
-
-
cities['United States'] = new Array();
-
cities['United States']['California'] = new Array('Los Angeles','San Francisco');
-
cities['United States']['Florida'] = new Array('Miami','Orlando');
-
cities['United States']['New York'] = new Array('Buffalo','new York');
-
-
-
function setStates() {
-
cntrySel = document.getElementById('country');
-
stateList = states[cntrySel.value];
-
changeSelect('state', stateList, stateList);
-
setCities();
-
}
-
-
function setCities() {
-
cntrySel = document.getElementById('country');
-
stateSel = document.getElementById('state');
-
cityList = cities[cntrySel.value][stateSel.value];
-
changeSelect('city', cityList, cityList);
-
}
-
-
function changeSelect(fieldID, newOptions, newValues) {
-
selectField = document.getElementById(fieldID);
-
selectField.options.length = 0;
-
for (i=0; i<newOptions.length; i++) {
-
selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]);
-
}
-
}
-
-
function addLoadEvent(func) {
-
var oldonload = window.onload;
-
if (typeof window.onload != 'function') {
-
window.onload = func;
-
} else {
-
window.onload = function() {
-
if (oldonload) {
-
oldonload();
-
}
-
func();
-
}
-
}
-
}
-
-
addLoadEvent(function() {
-
setStates();
-
});
-
</script>
-
-
</head>
-
-
<body>
-
-
<form>
-
<table>
-
<tr>
-
<td style="text-align: left;">Country:</td>
-
<td style="text-align: left;">
-
<select name="country" id="country" onchange="setStates();">
-
<option value="Philippines">Philippines</option>
-
<option value="Canada">Canada</option>
-
<option value="United States">United States</option>
-
</select>
-
</td>
-
</tr><tr>
-
<td style="text-align: left;">State:</td>
-
<td style="text-align: left;">
-
<select name="state" id="state" onchange="setCities();">
-
<option value="">Please select a Country</option>
-
</select>
-
</td>
-
</tr><tr>
-
<td style="text-align: left;">City:</td>
-
<td style="text-align: left;">
-
<select name="city" id="city">
-
<option value="">Please select a Country</option>
-
</select>
-
</td>
-
</tr>
-
</table>
-
</form>
-
-
-
-
</body>
-
</html>
-
-
-
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.
Hard code mapping of country, state and city in your code, see above javascript example.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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...
|
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...
|
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...
|
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) :...
| |
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.
|
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...
|
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
|
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
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| | |