SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically list all states for selected country

    Would it be possible for someone to point me towards a script or show me how to automatically list all the states in a selected country.

    example: http://faceparty.com/join.asp

    if you scroll down on that page and select a country it will dynamically update the states selection underneath to show the states for the selected country.

    Any help would be greatly appreciated.
    hmm...

  2. #2
    SitePoint Evangelist
    Join Date
    Sep 2003
    Location
    San Diego, CA
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, looking at the code for the site, this is what tey use
    Code:
    <script language="JavaScript">
    bInt6=new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54);
    bInt5=new Array(0,67,68,69,70,71,72,73,74,78,75,76,77);bInt2=new Array(0,55,56,57,58,59,60,61,62,63,64,65,66);
    bStr6=new Array(bCA,"Alabama","Alaska","Arizona","Arkansas","Armed Forces Asia","Armed Forces Europe","Armed Forces Pacific","California","Colorado","Connecticut","Delaware","District of Columbia","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming");
    bStr5=new Array(bCU,"East & East Anglia","East Midlands","London & Thames","North East","North West","South & South East","South West","West Midlands","Yorkshire","Wales","Scotland","Northern Ireland");bStr2=new Array(bCC,"Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland","Northwest Territories","Nova Scotia","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon");
    function bgS(bgC,bgR){bgC=parseInt(bgC);
    for(bgLp=0;bgLp<54;bgLp++){bgR.options[1]=null;}
    if(bgC==5&&isie){hs('cth','visible');}else{hs('cth','hidden');}
    if(bgC==6||bgC==5||bgC==2){var bInt=eval('bInt'+bgC);var bStr=eval('bStr'+bgC);var bLen=bInt.length;
    for(bgLp=0;bgLp<bLen;bgLp++){bgR.options[bgLp]=new Option(bStr[bgLp],bInt[bgLp]);}
    }else{bgR.options[0]=new Option(bNa,0);}}
    </script>
    The code above would go in your head section. For your drop down box you would put an onchange event, so in the code for the drop down box, you would put (with slight modifications)
    Code:
    onchange=bgS(window.document.FORMNAME.THISDROPDOWNBOXNAME.options[selectedIndex].value,window.document.FORMNAME.STATEBOXNAME);
    Of course you would change the FORMNAME, THISDROPDOWNBOXNAME, and STATEBOXNAME to the cordinating names!

  3. #3
    The Jellophonic Autobrain CHeeSeBLiND's Avatar
    Join Date
    Jul 2001
    Location
    Bolton, England
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried that and whenever i change the country, nothing happens to the state at all.

    HTML Code:
    <form action="search.php?action=search" method="POST" name="search">
     Country:
     <select name=country size=1 onChange="bgS(window.document.search.country.options[selectedIndex].value,window.document.search.region);">
       <option value="" selected>Please Choose</option>
       <option value="">--------------------------</option>
       <option value="5">United Kingdom</option>
       <option value="6">United States</option>
       <option value="2">Canada</option>
     </select>
     <br>
     Region:
     <select name=region size=1>
       <option value= selected>Please Choose</option>
     </select>
     <br>
     <input type="submit" value="Search">
     </form>
    hmm...

  4. #4
    SitePoint Evangelist
    Join Date
    Sep 2003
    Location
    San Diego, CA
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using the following for the country drop-down box:
    Code:
    <select name=country class=sm size=1 onChange="bgS(window.document.search.country.options[selectedIndex].value,window.document.search.region);">
    <option value=0 >Please Choose</option><option value=0>------------------------------<option value=186>Afghanistan
    <option value=120>Albania<option value=85>Algeria<option value=194>American Samoa<option value=113>Andorra
    <option value=191>Angola<option value=188>Anguilla<option value=193>Antarctica<option value=187>Antigua + Barbuda
    <option value=17>Argentina<option value=189>Armenia<option value=195>Aruba<option value=185>Ascension Is.
    <option value=192>Asia Pacific<option value=1>Australia<option value=22>Austria<option value=89>Azerbaijan
    <option value=108>Bahamas<option value=52>Bahrain<option value=92>Bangladesh<option value=59>Barbados
    <option value=93>Belarus<option value=13>Belgium<option value=201>Belize<option value=102>Benin
    <option value=197>Bermuda<option value=198>Bhutan<option value=115>Bolivia<option value=83>Bosnia + Herzegovina
    <option value=200>Botswana<option value=199>Bouvet Is.<option value=8>Brazil<option value=107>British Indian Oc. Ter.
    <option value=68>Brunei<option value=51>Bulgaria<option value=111>Burkina Faso<option value=196>Burundi
    <option value=2>Canada<option value=239>Cambodia<option value=168>Cameroon<option value=170>Cap Verde
    <option value=244>Cayman Is.<option value=204>Central African Rep.<option value=140>Chad<option value=18>Chile
    <option value=40>China<option value=171>Christmas Is.<option value=202>Cocos Is.<option value=33>Colombia
    <option value=241>Comoros<option value=165>Congo<option value=167>Cook Is.<option value=87>Costa Rica
    <option value=166>Cote d'Ivoire<option value=71>Croatia<option value=169>Cuba<option value=48>Cyprus
    <option value=50>Czech Rep.<option value=16>Denmark<option value=172>Djibouti<option value=173>Dominica
    <option value=54>Dominican Rep.<option value=150>East Timor<option value=121>Ecuador<option value=63>El Salvador
    <option value=49>Egypt<option value=227>Equatorial Guinea<option value=175>Eritrea<option value=39>Estonia
    <option value=176>Ethiopia<option value=98>Falkland Is.<option value=179>Faroe Is.<option value=177>Fiji
    <option value=28>Finland<option value=3>France<option value=182>French Guiana<option value=123>French Polynesia
    <option value=142>French Southern Ter.<option value=180>Gabon<option value=86>Gambia<option value=70>Georgia
    <option value=4>Germany<option value=97>Ghana<option value=106>Gibraltar<option value=45>Greece
    <option value=184>Greenland<option value=181>Grenada<option value=226>Guadeloupe<option value=81>Guam
    <option value=56>Guatemala<option value=225>Guinea<option value=229>Guinea-Bissau
    <option value=230>Guyana<option value=233>Haiti<option value=231>Heard + McDonald Is.<option value=232>Honduras
    <option value=32>Hong Kong<option value=46>Hungary<option value=65>Iceland
    <option value=42>India<option value=47>Indonesia<option value=79>Iran<option value=235>Iraq
    <option value=36>Ireland<option value=9>Israel<option value=12>Italy<option value=237>Jamaica
    <option value=37>Japan<option value=74>Jordan<option value=110>Kazakhstan
    <option value=84>Kenya<option value=240>Kiribati<option value=243>Korea, North<option value=41>Korea, South
    <option value=60>Kuwait<option value=238>Kyrgyzstan<option value=205>Laos<option value=64>Latvia
    <option value=77>Lebanon<option value=209>Lesotho<option value=208>Liberia<option value=101>Libya
    <option value=207>Liechtenstein<option value=34>Lithuania<option value=80>Luxembourg<option value=72>Macau
    <option value=75>Macedonia<option value=210>Madagascar<option value=219>Malawi<option value=43>Malaysia
    <option value=218>Maldives<option value=212>Mali<option value=58>Malta<option value=211>Marshall Is.
    <option value=215>Martinique<option value=216>Mauritania<option value=103>Mauritius<option value=128>Mayotte
    <option value=10>Mexico<option value=178>Micronesia<option value=118>Moldova<option value=114>Monaco
    <option value=76>Mongolia<option value=217>Montserrat<option value=82>Morocco<option value=109>Mozambique
    <option value=213>Myanmar<option value=119>Namibia<option value=223>Nauru<option value=7>Netherlands
    <option value=190>Netherlands Antilles<option value=96>Nepal<option value=220>New Caledonia<option value=27>New Zealand
    <option value=117>Nicaragua<option value=221>Niger<option value=94>Nigeria<option value=224>Niue
    <option value=222>Norfolk Is.<option value=214>Northern Mariana Is.<option value=24>Norway<option value=99>Oman
    <option value=53>Pakistan<option value=126>Palau<option value=112>Palestinian Ter.<option value=78>Panama
    <option value=132>Papua New Guinea<option value=116>Paraguay<option value=31>Peru<option value=21>Philippines
    <option value=125>Pitcairn Is.<option value=14>Poland<option value=25>Portugal<option value=62>Puerto Rico
    <option value=95>Qatar<option value=163>Reunion Is.<option value=57>Romania<option value=55>Russia
    <option value=160>Rwanda<option value=151>St. Helena<option value=242>St. Kitts + Nevis<option value=206>St. Lucia
    <option value=127>St. Pierre + Miquelon<option value=161>St. Vincent + G/dines<option value=141>San Marino<option value=137>Sao Tome + Principe
    <option value=91>Saudi Arabia<option value=105>Senegal<option value=156>Seychelles<option value=143>Sierra Leone
    <option value=26>Slovenia<option value=157>Solomon Is.<option value=139>Somalia<option value=23>South Africa
    <option value=228>S. Georgia + S/w Is.<option value=11>Spain<option value=19>Singapore<option value=44>Slovakia
    <option value=100>Sri Lanka<option value=155>Sudan<option value=138>Suriname<option value=148>Svalbard + Jan Mayen
    <option value=134>Swaziland<option value=15>Sweden<option value=20>Switzerland<option value=135>Syria
    <option value=153>Tanzania<option value=29>Taiwan<option value=145>Tajikistan<option value=38>Thailand
    <option value=144>Togo<option value=146>Tokelau<option value=149>Tonga<option value=69>Trinidad + Tobago
    <option value=90>Tunisia<option value=30>Turkey<option value=147>Turkmenistan<option value=136>Turks + Caicos Is.
    <option value=152>Tuvalu<option value=154>Uganda<option value=61>Ukraine<option value=104>United Arab Emirates
    <option value=5>United Kingdom<option value=6 selected>United States<option value=66>Uruguay<option value=158>US Minor Outlying Is.
    <option value=159>Uzbekistan<option value=129>Vanuatu<option value=73>Vatican City<option value=35>Venezuela
    <option value=88>Vietnam<option value=162>Virgin Is.<option value=130>Wallis + Futuna Is.<option value=174>Western Sahara
    <option value=131>Western Samoa<option value=133>Yemen<option value=67>Yugoslavia<option value=203>Zaire<option value=122>Zambia
    <option value=124>Zimbabwe</select>

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...had something like this lying around

    See if you can use it. The place names need a little editing. [zip to follow]
    Attached Files Attached Files
    Last edited by adios; Apr 1, 2004 at 10:15.
    ::: certified wild guess :::

  6. #6
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    Belgian in Mexico
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can get a countries, states and cities list, along when other info may be useful, depending on your needs), like population, GNP, languages, life expectancy and more... from http://www.assemblysys.com/worldstats/countries_DB.php

    Also you can receive the PHP code for the countries, states and cities list with filtering (when you select the country, it populates the states list and when you select the state, it populates the cities list).

    Hope that helps.
    Last edited by mniessen; May 5, 2004 at 05:13.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •