Chain select
Posted: Mon Nov 14, 2011 11:42 am
Hi, why function getCities() doesn't work, although first function works?
Code: Select all
<html>
<head>
<script type="text/javascript">
function getStates(){
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest;
} catch (e)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp)
{
var form = document['form1'];
var country = form['country'].value;
xmlhttp.open("GET", "http://localhost/projects/jquery_chosen/harvesthq-chosen-875c800/test/test7/prototype2/getStates.php?country="+country, true);
xmlhttp.onreadystatechange = function()
{
if(this.readyState == 4)
{
var s = document.createElement("select");
s.name = "state";
s.innerHTML = this.responseText;
form.replaceChild(s, form['state']);
}
}
xmlhttp.send(null);
}
}
function getCities(){
alert ("city");
}
</script>
</head>
<body>
<form name="form1" method="POST">
<select name="country" onChange="window.getStates()">
<option disabled>Select Country</option>
<option value="usa">USA</option>
<option value="uk">UK</option>
</select>
<select name="state" onChange="window.getCities()">
</select>
<select name="city">
</select>
</form>
</body>
</html>