So I have a city dropdown which is populated by an onchange, I am trying to get it so that it doesn't require the onchange every time the page reloads, since it is a form.
this is the states dropdown, which works.
<p id=stateDiv><label>State</label></p><p><select name='States' id='States' onchange='getCity(this.value)'>
" . $states . "
</select></p>";
this is the city drop down function call which does not work. I am new to javascript, so I am not sure about how to format a call with php.
if($state==""){
echo '<p id="citydiv"></p>';
}else{
echo '<p id="citydiv"><script type="text/javascript">getCity('.$state.');</script></p>';
}
getCity function
function getCity(stateId)
{
var strURL="findcity.php?state="+stateId;
var req = getXMLHTTP();
if (req)
{
req.onreadystatechange = function()
{
if (req.readyState == 4) // only if "OK"
{
if (req.status == 200)
{
document.getElementById('citydiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}