Forums
This topic is locked
Region/Country/State Chooser
Posted 13 Jul 2004 06:12:00
1
has voted
13 Jul 2004 06:12:00 hearts of hope posted:
Can someone please help me with the country chooser script. i really need to have a seperate state field but have no idea how to add this. I have looked for other scripts that have Region/Country/State fields but have not been able to find any that are cross browser compatible. I plan to use the script in a membership application form which submits the info to a 'excel type' database. I should point out, I do not want to list states/provinces for every country (probably just for US/Canada & Australia) but would like to include the 'other' function where a user would enter his state/province if it was not listed, I would also need to this option for the country field as more than likely I wont have a complete country list.I would really appreciate it if someone could point me in the direction of a script that does this or can advise me of the changes I need to make to 'country chooser' to get it to work this way
Thankx in advance
Csaba
<pre id=code><font face=courier size=2 id=code>
<html>
<head><script LANGUAGE="JavaScript">
var africaArray = new Array("('Select country','',true,true)",
"('South Africa')",
"('Other')"
var middleeastArray = new Array("('Select country','',true,true)",
"('U. A. Emirates')",
"('Other')"
var asiaArray = new Array("('Select country','',true,true)",
"('Vietnam')",
"('Other')"
var europeArray = new Array("('Select country','',true,true)",
"('United Kingdom')",
"('Other')"
var australiaArray = new Array("('Select country','',true,true)",
"('Australia')",
"('New Zealand')",
"('Other')"
var lamericaArray = new Array("('Select country','',true,true)",
"('Panama')",
"('Other')"
var namericaArray = new Array("('Select country','',true,true)",
"('Canada')",
"('USA')",
"('Other')"
var samericaArray = new Array("('Select country','',true,true)",
"('Venezuela')",
"('Other')"
function populateCountry(inForm,selected) {
var selectedArray = eval(selected + "Array"
while (selectedArray.length < inForm.country.options.length) {
inForm.country.options[(inForm.country.options.length - 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval("inForm.country.options[i]=" + "new Option" + selectedArray[i]);
}
if (inForm.region.options[0].value == '') {
inForm.region.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0);
}
}
}
}
}
function populateUSstate(inForm,selected) {
var stateArray = new Array("('Select State','',true,true)",
"('West Virginia')",
"('Wisconsin')",
"('Wyoming')"
if (selected == 'USA') {
for (var i=0; i < stateArray.length; i++) {
eval("inForm.country.options[i]=" + "new Option" + stateArray[i]);
}
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0)
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0)
}
}
}
}
else {
}
if (selected == 'Other') {
newCountry = "";
while (newCountry == ""{
newCountry=prompt ("Please enter the name of your country.", ""
}
if (newCountry != null) {
inForm.country.options[(inForm.country.options.length-1)]=new Option(newCountry,newCountry,true,true);
inForm.country.options[inForm.country.options.length]=new Option('Other, not listed','Other');
}
}
if(inForm.country.options[0].text == 'Select country') {
inForm.country.options[0]= null;
}
}
</script>
<title>Country and Area</title>
</head>
<body>
<form name="globe">
<div align="center"><center><p><select name="region"
onChange="populateCountry(document.globe,document.globe.region.options[document.globe.region.selectedIndex].value)"
size="1">
<option selected value>Select Region</option>
<option value="asia">Asia</option>
<option value="africa">Africa</option>
<option value="australia">Australia</option>
<option value="europe">Europe</option>
<option value="middleeast">Middle East</option>
<option value="lamerica">Latin America</option>
<option value="namerica">North America</option>
<option value="samerica">South America</option>
</select> <select name="country"
onChange="populateUSstate(document.globe,document.globe.country.options[document.globe.country.selectedIndex].text)"
size="1">
</select></p>
</center></div>
</form>
</body>
</html>
</font id=code></pre id=code>
Replies
Replied 21 Jul 2004 10:45:43
21 Jul 2004 10:45:43 Oleksandr (Alex) Manzyukov replied: