フォームの選択値が変更されたときに ajax 関数を使用しようとしています。選択した州に基づいて都市のリストが表示されます。しかし、それは何もしていません。
都市.php
<script type="text/javascript">
function change_state(str)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("cityselector").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","changestate.php?changed_state="+str,true);
xmlhttp.send();
}
</script>
<div class="city-switcher">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" id="cityselector" style="position: absolute; top: 15px; left: 310px;">
<select name="city" onchange="document.forms['cityselector'].submit()" style="font-size: 1.5em;">
<?php
$selected_state = select_single("STATE", "locations", "NAME='$location'", "");
$cities = select("*", "locations", "STATE='$selected_state'", "");
foreach ($cities as $city){
echo '<option value="'.$city['NAME'].'" '.($location == $city['NAME'] ? 'selected="selected"' : '').'>'.$city['NAME'].'</option>';
}
?>
</select>
</form>
<select name="state" onchange="change_state(this.value)" style="font-size: 1.5em;">
<?php
$states = select("DISTINCT STATE", "locations", "", "ORDER BY STATE ASC");
$selected_state = select_single("STATE", "locations", "NAME='$location'", "");
foreach ($states as $state){
echo '<option value="'.$state['STATE'].'" '.($selected_state == $state['STATE'] ? 'selected="selected"' : '').'>'.$state['STATE'].'</option>';
}
?>
</select>
</div>
changestate.php
<?php
include '../config.php';
include '../library.php';
$changed_state = $_GET['changed_state'];
echo '<select name="city" onchange="document.forms[\'cityselector\'].submit()" style="font-size: 1.5em;">';
$cities = select("*", "locations", "STATE='$changed_state'", "");
foreach ($cities as $city){
echo '<option value="'.$city['NAME'].'" '.($location == $city['NAME'] ? 'selected="selected"' : '').'>'.$city['NAME'].'</option>';
}
echo '</select>';
?>
誰が私が間違っているのか教えてもらえますか。
ありがとう、