Forum Moderators: open
Heres the HTML bit that does not seem to be working - my problem is that the 'city' is not being sent/captured (country is):
-----------------------------
<input name="button" type="button" style="font-size:12px;color:#ffffff;font-family:verdana;background-color:#6666FF;" onClick="window.location.href='/' + document.getElementById('country').value + '/' + document.getElementById('city').value + '/';" value="GO!">
-----------------------------
<script language="javascript">
var countries=new Array();
countries[0]=new Array();
countries[0]['country']='United Kingdom';
countries[0]['cities']=['London','Manchester','Birmingham','Liverpool','Edinburgh','Cardiff','Belfast'];
countries[1]=new Array();
countries[1]['country']='United States';
countries[1]['cities']=['Washington DC','New York','Los Angeles','Chicago'];
countries[2]=new Array();
countries[2]['country']='Australia';
countries[2]['cities']=['Canberra','Melbourne','Sydney','Brisbane'];
countries[3]=new Array();
countries[3]['country']='Japan';
countries[3]['cities']=['Tokyo','Osaka','Fukuoka','Sendai','Sapporo'];
function initBoxes(box1,box2) {
var country=document.getElementById(box1);
var city=document.getElementById(box2);
for (i=0; i<countries.length; i++) {
var x=document.createElement('option');
var y=document.createTextNode(countries[i]['country']);
if (window.attachEvent) { // for IE
x.setAttribute('value',y.nodeValue);
}
x.appendChild(y);
country.appendChild(x);
}
country.onchange=function() {
if(this.value!="") {
var list=document.getElementById(box2);
while (list.childNodes[0]) {
list.removeChild(list.childNodes[0])
}
fillBox2(city,this.value);
}
}
fillBox2(city,country.value);
}
function fillBox2(box2,country) {
for (i=0; i<countries.length; i++) {
if (countries[i]['country']==country) {
var cities=countries[i]['cities'];
}
}
for (i=0; i<cities.length; i++) {
var x=document.createElement('option');
var y=document.createTextNode(cities[i]);
x.appendChild(y);
box2.appendChild(x);
}
}
window.onload=function() {initBoxes('country','city');}
</script>
<p><label>country: <select id="country" name="country">
</select></label></p>
<p>
<label>city:
<select id="city" name="city">
</select>
</label>
</p>
<p>
<input name="button" type="button" style="font-size:12px;color:#ffffff;font-family:verdana;background-color:#6666FF;" onClick="window.location.href='/' + document.getElementById('country').value + '/' + document.getElementById('city').value + '/';" value="GO!">
</form></p>