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>
&lt;html&gt;
&lt;head&gt;&lt;script LANGUAGE="JavaScript"&gt;

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 &lt; inForm.country.options.length) {
inForm.country.options[(inForm.country.options.length - 1)] = null;
}
for (var i=0; i &lt; 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) &lt; 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 &lt; stateArray.length; i++) {
eval("inForm.country.options[i]=" + "new Option" + stateArray[i]);
}
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) &lt; 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;
}
}
&lt;/script&gt;

&lt;title&gt;Country and Area&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form name="globe"&gt;
&lt;div align="center"&gt;&lt;center&gt;&lt;p&gt;&lt;select name="region"
onChange="populateCountry(document.globe,document.globe.region.options[document.globe.region.selectedIndex].value)"
size="1"&gt;
&lt;option selected value&gt;Select Region&lt;/option&gt;
&lt;option value="asia"&gt;Asia&lt;/option&gt;
&lt;option value="africa"&gt;Africa&lt;/option&gt;
&lt;option value="australia"&gt;Australia&lt;/option&gt;
&lt;option value="europe"&gt;Europe&lt;/option&gt;
&lt;option value="middleeast"&gt;Middle East&lt;/option&gt;
&lt;option value="lamerica"&gt;Latin America&lt;/option&gt;
&lt;option value="namerica"&gt;North America&lt;/option&gt;
&lt;option value="samerica"&gt;South America&lt;/option&gt;
&lt;/select&gt; &lt;select name="country"
onChange="populateUSstate(document.globe,document.globe.country.options[document.globe.country.selectedIndex].text)"
size="1"&gt;
&lt;/select&gt;&lt;/p&gt;
&lt;/center&gt;&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</font id=code></pre id=code>

Replies

Replied 21 Jul 2004 10:45:43
21 Jul 2004 10:45:43 Oleksandr (Alex) Manzyukov replied:

Reply to this topic