<select id="country" name="country" onChange="getState(this.value)" class="dropdown">
<option value="0">Select Country</option>
<?php
echo $country;
?>
</select>
上面的代码从数据库中获取国家,根据使用 ajax 的国家,我使用下面的代码创建了一个下拉列表,我无法插入状态值。如何在 php dbpage 中获取状态值以插入状态值
<div id="statediv" >
<select id="ddlstate" name="ddlstate" class="dropdown" value="0">
<option>Select Country First</option>
</select>
</div>
this is my full ajax code
function getState(countryId)
{
var strURL="findState.php?country="+countryId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
document.getElementById('statediv').innerHTML=req.responseText;
}
else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
这是 findState.php
<?php $country=intval($_GET['country']);
$query="SELECT stateid,statename FROM state WHERE countryid='$country'";
$result=mysql_query($query);
?>
<select name="state" onchange="getCity(<?php echo $country?>,this.value)">
<option>Select State</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value=<?php echo $row['stateid']?>>
<?php echo $row['statename']?>
</option>
<?php } ?>
</select>