这都是为什么啊为什么啊
<script language="javascript">
function college2major(collegeid)
{
var allcount=0;
majorarray=new array();
<?php
$sql="select * from major";
$result=mysql_query($sql);
$count=0;
while($myrow=mysql_fetch_array($result))
{
?>
majorarray[<?php =$count ?>]=new array(""<?php =$myrow['major_id']?>","<?php =$myrow['major_name'] ?>","<?php =$myrow['college_id'] ?>" );
<?php
$count++;
}
echo "allcount=$count";
?>
document.studentform.major.length=0;
document.studentform.major.options[document.studentform.major.length]=new option("选择专业","");
var collegeid=collegeid;
var i;
for(i=1;i<allcount;i++)
{
if(majorarray[i][2]==collegeid)
{
document.studentform.major.options[document.studentform.major.length]=new option(majorarray[i][1],majorarray[i][0]);
}
}
}function major2class(majorid)
{
var allcount=0;
classarray=new array();
<?php
$sql="select * from class";
$result=mysql_query($sql);
$count=0;
while($myrow=mysql_fetch_array($result))
{
?>
classarray[<?php =$count ?>]=new array(""<?php =$myrow['class_id']?>","<?php =$myrow['class_name'] ?>","<?php =$myrow['major_id'] ?>" );
<?php
$count++;
}
echo "allcount=$count";
?>
document.studentform.class.length=0;
document.studentform.class.options[document.studentform.class.length]=new option("选择班级","");
var majorid=majorid;
var i;
for(i=1;i<allcount;i++)
{
if(classarray[i][2]==majorid)
{
document.studentform.class.options[document.studentform.class.length]=new option(classarray[i][1],classarray[i][0]);
}
}
}
</script>
<select name="college" onchange="college2major(this.options[this.selectedIndex].value)">
<option selected value="">选择学院</option>
<?php
$sql="select * from college";
$result=mysql_query($sql);
while($myrow =mysql_fetch_array($result))
{
?>
<option value="<?php $myrow 1["college_id"];?>">
<?php echo $myrow ["college_name"];?>
</option>
<?php }?>
</select>
<select name="major" id="major" onchange="major2class(this.options[this.selectedIndex].value)">
<option selected value="">选择专业</option>
</select><select name="class"id="class" >
<option selected value="">选择班级</option>
</select>数据库中的college里college_id是主键;major里major_id是主键,college_id是college里的外键;class里的class_id是主键,major_id是major里的外键各位大侠,我咋不能实现关联,哪错了??求解

解决方案 »

  1.   

    你的下拉列表选择项改变后,并没有事件处理,你要加个onchange事件
      

  2.   

    我有onchange啊 <select name="college" onchange="college2major(this.options[this.selectedIndex].value)">
    就是这样去调用上面定义的函数啊。感觉理论上应该是可以的,但是不知道为啥不行。。
    求解啊。