我有一个两级动态list.its工作正常现在问题是我无法捕获第二个列表值...我想你们可以帮助我..
这是表格
<?php
require 'db.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>Selection Form</title>
</head>
<body>
<form action="/display/check.php" method="get"/>
<table>
<tr>
<td>Select Semester</td>
<td>
<select id=semesterdd onChange="change_semester()" name="sem">
<option>
Select
</option>
<?php
$result = $mysqli->query("SELECT * FROM subjects ORDER BY semester ASC") or die($mysqli->error());
while($row=mysqli_fetch_array($result))
{
?>
<option ><?php echo $row["semester"];?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>
Select Subjects:
</td>
<td>
<div id="subjectid">
<select name='sub'>
<option>
Select
</option>
</select>
</div>
</td>
</tr>
</table>
<input type="submit" value="submit">
</form>
<script type="text/javascript">
function change_semester()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax3.php?semester="+document.getElementById("semesterdd").value,false);
xmlhttp.send(null);
alert(xmlhttp.responseText);
document.getElementById("subjectid").innerHTML=xmlhttp.responseText;
}
</script>
</body>
这是ajax文件
<?php
require 'db.php';
$semester=$_GET["semester"];
if($semester!="")
{
$result=$mysqli->query("SELECT * FROM subjects WHERE semester=$semester ORDER BY subject ASC") or die($mysqli->error());
echo "<select>";
while($row=mysqli_fetch_array($result))
{
echo "<option value=>";echo $row["subject"];echo "</option>";
//echo '<option value="'.$row['code'].'">'.$row['subject'].'</option>';
}
echo "</select>";
}
?>
这是响应..它捕获了学期选项,但为什么不选择子选项?
http://127.0.0.1/display/check.php?sem=3
答案 0 :(得分:0)
xmlhttp.open("GET","ajax3.php?semester="+document.getElementById("semesterdd").value+"&sub="+document.getElementById("[subjectid]").value,false);
将[subjectid]更改为您想要的任何ID。