Depending on how many unique city entries you have per state, this Javascript could get pretty slow (10-20 is cool, 100+ would be real slow). But in any event you should be building the arrays on the fly... I'll save you a step and cut out the three-tiered structure on JavaScript Source. Below is a two-tiered, which is closer to where you want tot get to (if country=US, pick a State, else just choose country)...
Code:
print qq~
<SCRIPT LANGUAGE="JavaScript">
function populateUSstate(inForm,selected) {
var stateArray = new Array("('Select...','',true,true)",
"('AL')",
"('AK')",
"('AZ')",
"('AR')",
"('CA')",
"('CO')",
"('CT')",
"('DE')",
"('DC')",
"('FL')",
"('GA')",
"('HI')",
"('ID')",
"('IL')",
"('IN')",
"('IA')",
"('KS')",
"('KY')",
"('LA')",
"('ME')",
"('MD')",
"('MA')",
"('MI')",
"('MN')",
"('MS')",
"('MO')",
"('MT')",
"('NE')",
"('NV')",
"('NH')",
"('NJ')",
"('NM')",
"('NY')",
"('NC')",
"('ND')",
"('OH')",
"('OK')",
"('OR')",
"('PA')",
"('RI')",
"('SC')",
"('SD')",
"('TN')",
"('TX')",
"('UT')",
"('VT')",
"('VI')",
"('WA')",
"('WV')",
"('WI')",
"('WY')");
if (selected == 'USA') {
for (var i=0; i < stateArray.length; i++) {
eval("inForm.State.options
=" + "new Option" + stateArray);
}
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 the country...", "");
}
if (newCountry != null) {
inForm.State.options[(inForm.State.options.length-1)]=new Option(newCountry,newCountry,true,true);
}
}
if(inForm.State.options[0].text == 'Select...') {
inForm.State.options[0]= null;
}
}
</script>
<select name="State" onChange="populateUSstate(document.form1,document.form1.State.options[document.form1.State.selectedIndex].text)">
<option selected value=''>Select...</option>
<option value='USA'>USA</option>
<option value='Canada'>Canada</option>
<option value='United Kingdom'>United Kingdom</option>
<option value='Israel'>Israel</option>
<option value='Other...'>Other...</option>
</select>~;