<!-- Paste this code into an external JavaScript file  -->/* This script and many more are available free online atThe JavaScript Source :: http://javascript.internet.comCreated by: Down Home Consulting :: http://downhomeconsulting.com *//*Country State Drop Downs v1.0.(c) Copyright 2005 Down Home Consulting, Inc.www.DownHomeConsulting.comPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, itness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.*/// If you have PHP you can set the post values like this//var postState = '<?= $_POST["state"] ?>';//var postCountry = '<?= $_POST["country"] ?>';var postState = '';var postCountry = '';// State table//// To edit the list, just delete a line or add a line. Order is important.// The order displayed here is the order it appears on the drop down.//var state = '\US:AK:Alaska|\US:AL:Alabama|\US:AR:Arkansas|\US:AS:American Samoa|\US:AZ:Arizona|\US:CA:California|\US:CO:Colorado|\US:CT:Connecticut|\US:DC:D.C.|\US:DE:Delaware|\US:FL:Florida|\US:FM:Micronesia|\US:GA:Georgia|\US:GU:Guam|\US:HI:Hawaii|\US:IA:Iowa|\US:ID:Idaho|\US:IL:Illinois|\US:IN:Indiana|\US:KS:Kansas|\US:KY:Kentucky|\US:LA:Louisiana|\US:MA:Massachusetts|\US:MD:Maryland|\US:ME:Maine|\US:MH:Marshall Islands|\US:MI:Michigan|\US:MN:Minnesota|\US:MO:Missouri|\US:MP:Marianas|\US:MS:Mississippi|\US:MT:Montana|\US:NC:North Carolina|\US:ND:North Dakota|\US:NE:Nebraska|\US:NH:New Hampshire|\US:NJ:New Jersey|\US:NM:New Mexico|\US:NV:Nevada|\US:NY:New York|\US:OH:Ohio|\US:OK:Oklahoma|\US:OR:Oregon|\US:PA:Pennsylvania|\US:PW:Palau|\US:RI:Rhode Island|\US:SC:South Carolina|\US:SD:South Dakota|\US:TN:Tennessee|\US:TX:Texas|\US:UT:Utah|\US:VA:Virginia|\US:VI:Virgin Islands|\US:VT:Vermont|\US:WA:Washington|\US:WI:Wisconsin|\US:WV:West Virginia|\US:WY:Wyoming|\US:AA:Military Americas|\US:AE:Military Europe/ME/Canada|\US:AP:Military Pacific|\PR:AD:Adjuntas|\PR:AG:Aguada|\PR:AL:Aguadilla|\PR:AB:Aguas Buenas|\PR:AT:Aibonito|\PR:AC:Anasco|\PR:AR:Arecibo|\PR:AY:Arroyo|\PR:BC:Barceloneta|\PR:BR:Barranquitas|\PR:BY:Bayamon|\PR:CR:Cabo Rojo|\PR:CG:Caguas|\PR:CY:Camuy|\PR:CV:Canovanas|\PR:CL:Carolina|\PR:CT:Catano|\PR:CA:Cayey|\PR:CI:Ceiba|\PR:CS:Ciales|\PR:CD:Cidra|\PR:CM:Coamo|\PR:CO:Comerio|\PR:CZ:Corozal|\PR:CB:Culebra|\PR:DR:Dorado|\PR:FJ:Fajardo|\PR:FL:Florida|\PR:GN:Guanica|\PR:GY:Guayama|\PR:GL:Guayanilla|\PR:GB:Guaynabo|\PR:GR:Gurabo|\PR:HT:Hatillo|\PR:HO:Hormigueros|\PR:HU:Humacao|\PR:IS:Isabela|\PR:JY:Jayuya|\PR:JD:Juana Diaz|\PR:JC:Juncos|\PR:LJ:Lajas|\PR:LS:Lares|\PR:LM:Las Marias|\PR:LP:Las Piedras|\PR:LZ:Loiza|\PR:LQ:Luquillo|\PR:MN:Manati|\PR:MC:Maricao|\PR:MU:Maunabo|\PR:MY:Mayaguez|\PR:MA:Moca|\PR:MV:Morovis|\PR:NG:Naguabo|\PR:MJ:Naranjito|\PR:OV:Orocovis|\PR:PL:Patillas|\PR:PU:Penuelas|\PR:PN:Ponce|\PR:QB:Quebradillas|\PR:RN:Rincon|\PR:RG:Rio Grande|\PR:SG:Sabana Grande|\PR:SL:Salinas|\PR:SN:San German|\PR:SJ:San Juan|\PR:SL:San Lorenzo|\PR:SS:San Sebastian|\PR:SI:Santa Isabel|\PR:TA:Toa Alta|\PR:TB:Toa Baja|\PR:TJ:Trujillo Alto|\PR:UT:Utuado|\PR:VA:Vega Alta|\PR:VB:Vega Baja|\PR:VQ:Vieques|\PR:VL:Villalba|\PR:YB:Yabucoa|\PR:YC:Yauco|\EL:EL: |\';// Country data table//// To edit the list, just delete a line or add a line. Order is important.// The order displayed here is the order it appears on the drop down.//var country = '\EL:Seleccione un país|\AF:Afghanistan|\AL:Albania|\DZ:Algeria|\AS:American Samoa|\AD:Andorra|\AO:Angola|\AI:Anguilla|\AQ:Antarctica|\AG:Antigua and Barbuda|\AR:Argentina|\AM:Armenia|\AW:Aruba|\AU:Australia|\AT:Austria|\AZ:Azerbaijan|\AP:Azores|\BS:Bahamas|\BH:Bahrain|\BD:Bangladesh|\BB:Barbados|\BY:Belarus|\BE:Belgium|\BZ:Belize|\BJ:Benin|\BM:Bermuda|\BT:Bhutan|\BO:Bolivia|\BA:Bosnia And Herzegowina|\XB:Bosnia-Herzegovina|\BW:Botswana|\BV:Bouvet Island|\BR:Brazil|\IO:British Indian Ocean Territory|\VG:British Virgin Islands|\BN:Brunei Darussalam|\BG:Bulgaria|\BF:Burkina Faso|\BI:Burundi|\KH:Cambodia|\CM:Cameroon|\CA:Canada|\CV:Cape Verde|\KY:Cayman Islands|\CF:Central African Republic|\TD:Chad|\CL:Chile|\CN:China|\CX:Christmas Island|\CC:Cocos (Keeling) Islands|\CO:Colombia|\KM:Comoros|\CG:Congo|\CD:Congo, The Democratic Republic O|\CK:Cook Islands|\XE:Corsica|\CR:Costa Rica|\CI:Cote d` Ivoire (Ivory Coast)|\HR:Croatia|\CU:Cuba|\CY:Cyprus|\CZ:Czech Republic|\DK:Denmark|\DJ:Djibouti|\DM:Dominica|\DO:Dominican Republic|\TP:East Timor|\EC:Ecuador|\EG:Egypt|\SV:El Salvador|\GQ:Equatorial Guinea|\ER:Eritrea|\EE:Estonia|\ET:Ethiopia|\FK:Falkland Islands (Malvinas)|\FO:Faroe Islands|\FJ:Fiji|\FI:Finland|\FR:France (Includes Monaco)|\FX:France, Metropolitan|\GF:French Guiana|\PF:French Polynesia|\TA:French Polynesia (Tahiti)|\TF:French Southern Territories|\GA:Gabon|\GM:Gambia|\GE:Georgia|\DE:Germany|\GH:Ghana|\GI:Gibraltar|\GR:Greece|\GL:Greenland|\GD:Grenada|\GP:Guadeloupe|\GU:Guam|\GT:Guatemala|\GN:Guinea|\GW:Guinea-Bissau|\GY:Guyana|\HT:Haiti|\HM:Heard And Mc Donald Islands|\VA:Holy See (Vatican City State)|\HN:Honduras|\HK:Hong Kong|\HU:Hungary|\IS:Iceland|\IN:India|\ID:Indonesia|\IR:Iran|\IQ:Iraq|\IE:Ireland|\EI:Ireland (Eire)|\IL:Israel|\IT:Italy|\JM:Jamaica|\JP:Japan|\JO:Jordan|\KZ:Kazakhstan|\KE:Kenya|\KI:Kiribati|\KP:Korea, Democratic People\'S Repub|\KW:Kuwait|\KG:Kyrgyzstan|\LA:Laos|\LV:Latvia|\LB:Lebanon|\LS:Lesotho|\LR:Liberia|\LY:Libya|\LI:Liechtenstein|\LT:Lithuania|\LU:Luxembourg|\MO:Macao|\MK:Macedonia|\MG:Madagascar|\ME:Madeira Islands|\MW:Malawi|\MY:Malaysia|\MV:Maldives|\ML:Mali|\MT:Malta|\MH:Marshall Islands|\MQ:Martinique|\MR:Mauritania|\MU:Mauritius|\YT:Mayotte|\MX:Mexico|\FM:Micronesia, Federated States Of|\MD:Moldova, Republic Of|\MC:Monaco|\MN:Mongolia|\MS:Montserrat|\MA:Morocco|\MZ:Mozambique|\MM:Myanmar (Burma)|\NA:Namibia|\NR:Nauru|\NP:Nepal|\NL:Netherlands|\AN:Netherlands Antilles|\NC:New Caledonia|\NZ:New Zealand|\NI:Nicaragua|\NE:Niger|\NG:Nigeria|\NU:Niue|\NF:Norfolk Island|\MP:Northern Mariana Islands|\NO:Norway|\OM:Oman|\PK:Pakistan|\PW:Palau|\PS:Palestinian Territory, Occupied|\PA:Panama|\PG:Papua New Guinea|\PY:Paraguay|\PE:Peru|\PH:Philippines|\PN:Pitcairn|\PL:Poland|\PT:Portugal|\PR:Puerto Rico|\QA:Qatar|\RE:Reunion|\RO:Romania|\RU:Russian Federation|\RW:Rwanda|\KN:Saint Kitts And Nevis|\SM:San Marino|\ST:Sao Tome and Principe|\SA:Saudi Arabia|\SN:Senegal|\XS:Serbia-Montenegro|\SC:Seychelles|\SL:Sierra Leone|\SG:Singapore|\SK:Slovak Republic|\SI:Slovenia|\SB:Solomon Islands|\SO:Somalia|\ZA:South Africa|\GS:South Georgia And The South Sand|\KR:South Korea|\ES:Spain|\LK:Sri Lanka|\NV:St. Christopher and Nevis|\SH:St. Helena|\LC:St. Lucia|\PM:St. Pierre and Miquelon|\VC:St. Vincent and the Grenadines|\SD:Sudan|\SR:Suriname|\SJ:Svalbard And Jan Mayen Islands|\SZ:Swaziland|\SE:Sweden|\CH:Switzerland|\SY:Syrian Arab Republic|\TW:Taiwan|\TJ:Tajikistan|\TZ:Tanzania|\TH:Thailand|\TG:Togo|\TK:Tokelau|\TO:Tonga|\TT:Trinidad and Tobago|\XU:Tristan da Cunha|\TN:Tunisia|\TR:Turkey|\TM:Turkmenistan|\TC:Turks and Caicos Islands|\TV:Tuvalu|\UG:Uganda|\UA:Ukraine|\AE:United Arab Emirates|\UK:United Kingdom|\GB:Great Britain|\US:United States|\UM:United States Minor Outlying Isl|\UY:Uruguay|\UZ:Uzbekistan|\VU:Vanuatu|\XV:Vatican City|\VE:Venezuela|\VN:Vietnam|\VI:Virgin Islands (U.S.)|\WF:Wallis and Furuna Islands|\EH:Western Sahara|\WS:Western Samoa|\YE:Yemen|\YU:Yugoslavia|\ZR:Zaire|\ZM:Zambia|\ZW:Zimbabwe|\';function TrimString(sInString) {  if ( sInString ) {    sInString = sInString.replace( /^\s+/g, "" );// strip leading    return sInString.replace( /\s+$/g, "" );// strip trailing  }}// Populates the country selected with the counties from the country listfunction populateCountry(defaultCountry) {  if ( postCountry != '' ) {    defaultCountry = postCountry;  }  var countryLineArray = country.split('|');  // Split into lines  var selObj = document.getElementById('countrySelect');  selObj.options[0] = new Option(' ','');  selObj.selectedIndex = 0;  for (var loop = 0; loop < countryLineArray.length; loop++) {    lineArray = countryLineArray[loop].split(':');    countryCode  = TrimString(lineArray[0]);    countryName  = TrimString(lineArray[1]);    if ( countryCode != '' ) {      selObj.options[loop + 1] = new Option(countryName, countryCode);    }    if ( defaultCountry == countryCode ) {      selObj.selectedIndex = loop + 1;    }  }}function populateState() {  var selObj = document.getElementById('stateSelect');  var foundState = false;  // Empty options just in case new drop down is shorter  if ( selObj.type == 'select-one' ) {    for (var i = 0; i < selObj.options.length; i++) {      selObj.options[i] = null;    }    selObj.options.length=null;    selObj.options[0] = new Option('Seleccione un estado o municipio','');    selObj.selectedIndex = 0;  }  // Populate the drop down with states from the selected country  var stateLineArray = state.split("|");  // Split into lines  var optionCntr = 1;  for (var loop = 0; loop < stateLineArray.length; loop++) {    lineArray = stateLineArray[loop].split(":");    countryCode  = TrimString(lineArray[0]);    stateCode    = TrimString(lineArray[1]);    stateName    = TrimString(lineArray[2]);  if (document.getElementById('countrySelect').value == countryCode && countryCode != '' ) {    // If it's a input element, change it to a select      if ( selObj.type == 'text' ) {        parentObj = document.getElementById('stateSelect').parentNode;        parentObj.removeChild(selObj);        var inputSel = document.createElement("SELECT");        inputSel.setAttribute("name","state");        inputSel.setAttribute("id","stateSelect");        parentObj.appendChild(inputSel) ;        selObj = document.getElementById('stateSelect');        selObj.options[0] = new Option('Seleccione un estado o municipio','');        selObj.selectedIndex = 0;      }      if ( stateCode != '' ) {        selObj.options[optionCntr] = new Option(stateName, stateCode);      }      // See if it's selected from a previous post      if ( stateCode == postState && countryCode == postCountry ) {        selObj.selectedIndex = optionCntr;      }      foundState = true;      optionCntr++    }  }  // If the country has no states, change the select to a text box  if ( ! foundState ) {    parentObj = document.getElementById('stateSelect').parentNode;    parentObj.removeChild(selObj);  // Create the Input Field    var inputEl = document.createElement("INPUT");    inputEl.setAttribute("id", "stateSelect");    inputEl.setAttribute("type", "text");    inputEl.setAttribute("name", "state");    inputEl.setAttribute("size", 20);    inputEl.setAttribute("value", postState);    parentObj.appendChild(inputEl) ;  }}function initCountry(country) {  populateCountry(country);  populateState();}
