我有一个包含 5 个下拉列表的表单,这些下拉列表是由 PHP 查询 MySql 数据库创建的。列表正在正确构建。
我希望用户能够从列表中进行选择,并根据所选值填写底部的表格。
它适用于第一个列表。
这是列表 1 中的代码
<td width="90">
<p><select size="1" name="D1" onchange="showStudent(this.value);">
<?php while(list($id, $student_id)=mysql_fetch_row($result1)) {
echo "
<option value=\"".$student_id."\">".$student_id."</option>";
}
?>
</select></p>
</td>
这是列表 2 中的代码
<td>
<p><select size="1" name="D2" onchange=”showStudent(this.value);” >
<?php while(list($id, $student_id)=mysql_fetch_row($result2)) {
echo "
<option value=\"".$student_id."\">".$student_id."</option>";
}
?>
</select></p>
</td>
这是javascript代码
<script type="text/javascript">
function CreateXmlHttpObject() { //function to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();//creates a new ajax object
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");//this is for IE browser
}
catch(e){
try{
req = new ActiveXObject("Msxml2.XMLHTTP");//this is for IE browser
}
catch(e1){
xmlhttp=false;//error creating object
}
}
}
return xmlhttp;
}
function showStudent(str)
{
// alert("Made it to show students"+ str);
if (str=="")
{
document.getElementById("student_data").innerHTML="";
return;
}
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("student_data").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","editstudent.php?d="+str,true);
xmlhttp.send();
}
</script>
如果我从第一个列表中选择,一切正常。但是,如果我从列表 2-5 中选择,则什么也没有。即使我先从其中一个中选择。我什至尝试更改函数的名称以匹配特定的列表名称,但仍然只有第一个有效。
我错过了什么?