<select id="country" name="country" onChange="getState(this.value)" class="dropdown">
<option value="0">Select Country</option>
<?php
echo $country;
?>
</select>
上記のコードはデータベースから国を取得します。ajaxを使用している国によると、以下のコードを使用して1つのドロップダウンを作成しましたが、状態値を挿入できません。状態値を挿入するためにphpdbpageで状態値を取得するにはどうすればよいですか?
<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>