hi friends...
in my php page 3 dropdownlist boxes are there.. ie country,state,c ity..
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...
11 17977
sounds like you need to use Javascript AJAX
onclick or onchange event on the first select box (countrys) will trigger the populate of the second dropbox (stats...) ... read here to get you started Markus 6,050
Recognized Expert Expert
AJAX is pointless for a task like this.
If you know ever possible country, state, city, etc., it'd be more efficient to store it in a javascript array, I'd expect.
numberwhun 3,509
Recognized Expert Moderator Specialist
Ok, so here is another solution. How about populating each country and its 2 letter code into an PHP associative array and then using it in a loop to produce the code needed for the select statement. Just an idea, seeing as how this is a PHP forum. :)
Or, you can just grab the finished product here.
You can do the same for states, in fact here is an example of what I was referring to above, but with a non-associative array.
With a few minor changes, you can produce a country select box that produces the same thing. As for the city select, that is quite a bit more entailed and would probably consist of a lot of tedious coding considering the number of cities in each country. The city might be better served as a user entered field.
Regards,
Jeff
numberwhun 3,509
Recognized Expert Moderator Specialist
Call me a bit anal but I wanted to share with you a couple of functions I wrote today. I am slowly building my repertoire of php functions and this thread prompted some additions for forms.
Here is the function I now have for producing a state select box: -
function state_selection() {
-
echo '<select name="state">'."\n";
-
-
$states = array(
-
'Alabama' => 'AL',
-
'Alaska' => 'AK',
-
'American Samoa' => 'AS',
-
'Arizona' => 'AZ',
-
'Arkansas' => 'AR',
-
'California' => 'CA',
-
'Colorado' => 'CO',
-
'Connecticut' => 'CT',
-
'Delaware' => 'DE',
-
'District of Columbia' => 'DC',
-
'Federated States Of Micronesia' => 'FM',
-
'Florida' => 'FL',
-
'Georgia' => 'GA',
-
'Hawaii' => 'HI',
-
'Idaho' => 'ID',
-
'Illinois' => 'IL',
-
'Indiana' => 'IN',
-
'Iowa' => 'IA',
-
'Kansas' => 'KS',
-
'Kentucky' => 'KY',
-
'Louisiana' => 'LA',
-
'Maine' => 'ME',
-
'Marshall Islands' => 'MH',
-
'Maryland' => 'MD',
-
'Massachusetts' => 'MA',
-
'Michigan' => 'MI',
-
'Minnesota' => 'MN',
-
'Mississippi' => 'MS',
-
'Missouri' => 'MO',
-
'Montana' => 'MT',
-
'Nebraska' => 'NE',
-
'Nevada' => 'NV',
-
'New Hampshire' => 'NH',
-
'New Jersey' => 'NJ',
-
'New Mexico' => 'NM',
-
'New York' => 'NY',
-
'North Carolina' => 'NC',
-
'North Dakota' => 'ND',
-
'Northern Mariana Islands' => 'MP',
-
'Ohio' => 'OH',
-
'Oklahoma' => 'OK',
-
'Oregon' => 'OR',
-
'Palau' => 'PW',
-
'Pennsylvania' => 'PA',
-
'Puerto Rico' => 'PR',
-
'Rhode Island' => 'RI',
-
'South Carolina' => 'SC',
-
'South Dakota' => 'SD',
-
'Tennessee' => 'TN',
-
'Texas' => 'TX',
-
'Utah' => 'UT',
-
'Vermont' => 'VT',
-
'Virgin Islands' => 'VI',
-
'Virginia' => 'VA',
-
'Washington' => 'WA',
-
'West Virginia' => 'WV',
-
'Wisconsin' => 'WI',
-
'Wyoming' => 'WY'
-
);
-
-
foreach ($states as $state_name => $state_abbr) {
-
echo '<option value="'.$state_abbr.'">'.$state_name.'</option>'."\n";
-
}
-
-
echo '</select>'."\n";
-
}
-
And here is the function I have for producing a country select list. I took this from the ISO so it should be pretty current: -
function country_selection() {
-
echo '<select name="country">'."\n";
-
-
$countries = array(
-
"AFGHANISTAN" => "AF",
-
"ÅLAND_ISLANDS" => "AX",
-
"ALBANIA" => "AL",
-
"ALGERIA" => "DZ",
-
"AMERICAN_SAMOA" => "AS",
-
"ANDORRA" => "AD",
-
"ANGOLA" => "AO",
-
"ANGUILLA" => "AI",
-
"ANTARCTICA" => "AQ",
-
"ANTIGUA_AND_BARBUDA" => "AG",
-
"ARGENTINA" => "AR",
-
"ARMENIA" => "AM",
-
"ARUBA" => "AW",
-
"AUSTRALIA" => "AU",
-
"AUSTRIA" => "AT",
-
"AZERBAIJAN" => "AZ",
-
"BAHAMAS" => "BS",
-
"BAHRAIN" => "BH",
-
"BANGLADESH" => "BD",
-
"BARBADOS" => "BB",
-
"BELARUS" => "BY",
-
"BELGIUM" => "BE",
-
"BELIZE" => "BZ",
-
"BENIN" => "BJ",
-
"BERMUDA" => "BM",
-
"BHUTAN" => "BT",
-
"BOLIVIA" => "BO",
-
"BOSNIA AND HERZEGOVINA" => "BA",
-
"BOTSWANA" => "BW",
-
"BOUVET ISLAND" => "BV",
-
"BRAZIL" => "BR",
-
"BRITISH INDIAN OCEAN TERRITORY" => "IO",
-
"BRUNEI DARUSSALAM" => "BN",
-
"BULGARIA" => "BG",
-
"BURKINA FASO" => "BF",
-
"BURUNDI" => "BI",
-
"CAMBODIA" => "KH",
-
"CAMEROON" => "CM",
-
"CANADA" => "CA",
-
"CAPE VERDE" => "CV",
-
"CAYMAN ISLANDS" => "KY",
-
"CENTRAL AFRICAN REPUBLIC" => "CF",
-
"CHAD" => "TD",
-
"CHILE" => "CL",
-
"CHINA" => "CN",
-
"CHRISTMAS ISLAND" => "CX",
-
"COCOS (KEELING) ISLANDS" => "CC",
-
"COLOMBIA" => "CO",
-
"COMOROS" => "KM",
-
"CONGO" => "CG",
-
"CONGO, THE DEMOCRATIC REPUBLIC OF THE" => "CD",
-
"COOK ISLANDS" => "CK",
-
"COSTA RICA" => "CR",
-
"CÔTE D'IVOIRE" => "CI",
-
"CROATIA" => "HR",
-
"CUBA" => "CU",
-
"CYPRUS" => "CY",
-
"CZECH REPUBLIC" => "CZ",
-
"DENMARK" => "DK",
-
"DJIBOUTI" => "DJ",
-
"DOMINICA" => "DM",
-
"DOMINICAN REPUBLIC" => "DO",
-
"ECUADOR" => "EC",
-
"EGYPT" => "EG",
-
"EL SALVADOR" => "SV",
-
"EQUATORIAL GUINEA" => "GQ",
-
"ERITREA" => "ER",
-
"ESTONIA" => "EE",
-
"ETHIOPIA" => "ET",
-
"FALKLAND ISLANDS (MALVINAS)" => "FK",
-
"FAROE ISLANDS" => "FO",
-
"FIJI" => "FJ",
-
"FINLAND" => "FI",
-
"FRANCE" => "FR",
-
"FRENCH GUIANA" => "GF",
-
"FRENCH POLYNESIA" => "PF",
-
"FRENCH SOUTHERN TERRITORIES" => "TF",
-
"GABON" => "GA",
-
"GAMBIA" => "GM",
-
"GEORGIA" => "GE",
-
"GERMANY" => "DE",
-
"GHANA" => "GH",
-
"GIBRALTAR" => "GI",
-
"GREECE" => "GR",
-
"GREENLAND" => "GL",
-
"GRENADA" => "GD",
-
"GUADELOUPE" => "GP",
-
"GUAM" => "GU",
-
"GUATEMALA" => "GT",
-
"GUERNSEY" => "GG",
-
"GUINEA" => "GN",
-
"GUINEA-BISSAU" => "GW",
-
"GUYANA" => "GY",
-
"HAITI" => "HT",
-
"HEARD ISLAND AND MCDONALD ISLANDS" => "HM",
-
"HOLY SEE (VATICAN CITY STATE)" => "VA",
-
"HONDURAS" => "HN",
-
"HONG KONG" => "HK",
-
"HUNGARY" => "HU",
-
"ICELAND" => "IS",
-
"INDIA" => "IN",
-
"INDONESIA" => "ID",
-
"IRAN, ISLAMIC REPUBLIC OF" => "IR",
-
"IRAQ" => "IQ",
-
"IRELAND" => "IE",
-
"ISLE OF MAN" => "IM",
-
"ISRAEL" => "IL",
-
"ITALY" => "IT",
-
"JAMAICA" => "JM",
-
"JAPAN" => "JP",
-
"JERSEY" => "JE",
-
"JORDAN" => "JO",
-
"KAZAKHSTAN" => "KZ",
-
"KENYA" => "KE",
-
"KIRIBATI" => "KI",
-
"KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF" => "KP",
-
"KOREA, REPUBLIC OF" => "KR",
-
"KUWAIT" => "KW",
-
"KYRGYZSTAN" => "KG",
-
"LAO PEOPLE'S DEMOCRATIC REPUBLIC" => "LA",
-
"LATVIA" => "LV",
-
"LEBANON" => "LB",
-
"LESOTHO" => "LS",
-
"LIBERIA" => "LR",
-
"LIBYAN ARAB JAMAHIRIYA" => "LY",
-
"LIECHTENSTEIN" => "LI",
-
"LITHUANIA" => "LT",
-
"LUXEMBOURG" => "LU",
-
"LAO PEOPLE'S DEMOCRATIC REPUBLIC" => "LA",
-
"LATVIA" => "LV",
-
"LEBANON" => "LB",
-
"LESOTHO" => "LS",
-
"LIBERIA" => "LR",
-
"LIBYAN ARAB JAMAHIRIYA" => "LY",
-
"LIECHTENSTEIN" => "LI",
-
"LITHUANIA" => "LT",
-
"LUXEMBOURG" => "LU",
-
"MACAO" => "MO",
-
"MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF" => "MK",
-
"MADAGASCAR" => "MG",
-
"MALAWI" => "MW",
-
"MALAYSIA" => "MY",
-
"MALDIVES" => "MV",
-
"MALI" => "ML",
-
"MALTA" => "MT",
-
"MARSHALL ISLANDS" => "MH",
-
"MARTINIQUE" => "MQ",
-
"MAURITANIA" => "MR",
-
"MAURITIUS" => "MU",
-
"MAYOTTE" => "YT",
-
"MEXICO" => "MX",
-
"MICRONESIA, FEDERATED STATES OF" => "FM",
-
"MOLDOVA, REPUBLIC OF" => "MD",
-
"MONACO" => "MC",
-
"MONGOLIA" => "MN",
-
"MONTENEGRO" => "ME",
-
"MONTSERRAT" => "MS",
-
"MOROCCO" => "MA",
-
"MOZAMBIQUE" => "MZ",
-
"MYANMAR" => "MM",
-
"NAMIBIA" => "NA",
-
"NAURU" => "NR",
-
"NEPAL" => "NP",
-
"NETHERLANDS" => "NL",
-
"NETHERLANDS ANTILLES" => "AN",
-
"NEW CALEDONIA" => "NC",
-
"NEW ZEALAND" => "NZ",
-
"NICARAGUA" => "NI",
-
"NIGER" => "NE",
-
"NIGERIA" => "NG",
-
"NIUE" => "NU",
-
"NORFOLK ISLAND" => "NF",
-
"NORTHERN MARIANA ISLANDS" => "MP",
-
"NORWAY" => "NO",
-
"OMAN" => "OM",
-
"PAKISTAN" => "PK",
-
"PALAU" => "PW",
-
"PALESTINIAN TERRITORY, OCCUPIED" => "PS",
-
"PANAMA" => "PA",
-
"PAPUA NEW GUINEA" => "PG",
-
"PARAGUAY" => "PY",
-
"PERU" => "PE",
-
"PHILIPPINES" => "PH",
-
"PITCAIRN" => "PN",
-
"POLAND" => "PL",
-
"PORTUGAL" => "PT",
-
"PUERTO RICO" => "PR",
-
"QATAR" => "QA",
-
"RÉUNION" => "RE",
-
"ROMANIA" => "RO",
-
"RUSSIAN FEDERATION" => "RU",
-
"RWANDA" => "RW",
-
"SAINT BARTHÉLEMY" => "BL",
-
"SAINT HELENA" => "SH",
-
"SAINT KITTS AND NEVIS" => "KN",
-
"SAINT LUCIA" => "LC",
-
"SAINT MARTIN" => "MF",
-
"SAINT PIERRE AND MIQUELON" => "PM",
-
"SAINT VINCENT AND THE GRENADINES" => "VC",
-
"SAMOA" => "WS",
-
"SAN MARINO" => "SM",
-
"SAO TOME AND PRINCIPE" => "ST",
-
"SAUDI ARABIA" => "SA",
-
"SENEGAL" => "SN",
-
"SERBIA" => "RS",
-
"SEYCHELLES" => "SC",
-
"SIERRA LEONE" => "SL",
-
"SINGAPORE" => "SG",
-
"SLOVAKIA" => "SK",
-
"SLOVENIA" => "SI",
-
"SOLOMON ISLANDS" => "SB",
-
"SOMALIA" => "SO",
-
"SOUTH AFRICA" => "ZA",
-
"SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS" => "GS",
-
"SPAIN" => "ES",
-
"SRI LANKA" => "LK",
-
"SUDAN" => "SD",
-
"SURINAME" => "SR",
-
"SVALBARD AND JAN MAYEN" => "SJ",
-
"SWAZILAND" => "SZ",
-
"SWEDEN" => "SE",
-
"SWITZERLAND" => "CH",
-
"SYRIAN ARAB REPUBLIC" => "SY",
-
"TAIWAN, PROVINCE OF CHINA" => "TW",
-
"TAJIKISTAN" => "TJ",
-
"TANZANIA, UNITED REPUBLIC OF" => "TZ",
-
"THAILAND" => "TH",
-
"TIMOR-LESTE" => "TL",
-
"TOGO" => "TG",
-
"TOKELAU" => "TK",
-
"TONGA" => "TO",
-
"TRINIDAD AND TOBAGO" => "TT",
-
"TUNISIA" => "TN",
-
"TURKEY" => "TR",
-
"TURKMENISTAN" => "TM",
-
"TURKS AND CAICOS ISLANDS" => "TC",
-
"TUVALU" => "TV",
-
"UGANDA" => "UG",
-
"UKRAINE" => "UA",
-
"UNITED ARAB EMIRATES" => "AE",
-
"UNITED KINGDOM" => "GB",
-
"UNITED STATES" => "US",
-
"UNITED STATES MINOR OUTLYING ISLANDS" => "UM",
-
"URUGUAY" => "UY",
-
"UZBEKISTAN" => "UZ",
-
"VANUATU" => "VU",
-
"VATICAN CITY STATE" => "VA",
-
"VENEZUELA, BOLIVARIAN REPUBLIC OF" => "VE",
-
"VIET NAM" => "VN",
-
"VIRGIN ISLANDS, BRITISH" => "VG",
-
"VIRGIN ISLANDS, U.S." => "VI",
-
"WALLIS AND FUTUNA" => "WF",
-
"WESTERN SAHARA" => "EH",
-
"YEMEN" => "YE",
-
"ZAMBIA" => "ZM",
-
"ZIMBABWE" => "ZW"
-
);
-
-
foreach ($countries as $country => $countryAbbr) {
-
echo '<option value="'.$countryAbbr.'">'.ucwords(strtolower($country)).'</option>'."\n";
-
}
-
-
echo '</select>'."\n";
-
}
-
I just felt like sharing. Hope that it helps!
Regards,
Jeff
thank you for all of you for your valuable suggestions..
i am having all the values in database.. how can i retrieve it according to selection?
my question is in onchange function whether i have to pass the entire table values to the javascript function.. and have to check the dropdown-selected value there in javascript code and to populate other list boxes accordingly???
can you clarity my doubt?? thank you in advance.
numberwhun 3,509
Recognized Expert Moderator Specialist @pinocchio123
If this has turned into a javascript question that I will move this question over to there to get your question answered.
Regards,
Jeff
@Markus
depends i say.
if every user use this drop list for sure then i would store the info in a js file even better from db as json.
but if not
no need to send to the user 20k js file with all the info, what if he wont use it??
ajax call here is the same.
acoder 16,027
Recognized Expert Moderator MVP @pinocchio123
If it's stored in a database, use Ajax to retrieve the corresponding state/city values. Try states to begin with and you can build on it to trigger the city drop-down change.
If the original country selection is blank, both state and city will be empty (no options). When a selection is made, make a call to a function which makes the request to you PHP page to populate the state drop-down with the correct options for the chosen country.
hi am seeking of exactly the same response. have you got the code ?...
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 a user selects
a country I could automatically populate the state drop down menu
Any help is appreciated
-- bg mahesh
|
by: jonny |
last post by:
Where can I find a dbase for index.PHP Country|State|Province|CITY
bjve@bjve.com
|
by: Deiter |
last post by:
State Machines and Coroutines
The other thread on goto: Lead me to want to ask... In the spirit of
state machines and coroutines, This n00b to C would like to know if
setjmp/longjmp are the only way to break out of a routine; leave the
function and re-enter the stack state.
I ask this because I've only briefly, as yet, reviewed these functions
and I believe longjmp will only return a designated int. Therefore I
would naively assume...
|
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 county or geographic region.
Are there any resources anyone may know out there where I can harvest
such information?
--
Tim http://www.ucs.mun.ca/~tmarshal/
|
by: ¥øÃZ½Þ¤j·Ý |
last post by:
Dear All
I have a question, in US, the address should displayed as
_____ (Room) ______ (Floor) ______ (Building)
______________________________ (Road)
______________________________ (District)
_________ Postal Code ___________ (City)
______________________________ (Province/State)
______________________________ Country
| |
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: dkyadav80 |
last post by:
Hi sir,
I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all city values should display in city selection field and when user select any one city value then this state of this city should be display auto in state
selection field without user selection. please solve my prolem.
Thank you.
|
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 state name should come from database according to country and in 3rd drop down cities name should come from database according to states.
I have tried many search engine but i could not get any proper info regarding this i mean some time i get whole...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: 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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| | |