您的位置:首页 > 编程语言 > PHP开发

php 加select下拉框三级联动

2010-11-06 08:13 375 查看
<script language="javascript">
var sbulist=new Array();
<?php
require("../include/Conn.php");
$st="select * from proclasstree where ParentsID!=0";
$rest=mysql_query($st,$link);
$num=mysql_num_rows($rest);
for($i=0;$i<$num;$i++)
{
$arr=mysql_fetch_array($rest);
?>
sbulist[<?php echo $i;?>]=new Array("<?php echo $arr["ParentsID"];?>","<?php echo $arr["ID"];?>","<?php echo $arr["ClassName"];?>");
<?php
}
?>
function checked1(locationid)
{
document.myform.ClassList_2.length=0;
document.myform.ClassList_2.options[0]=new Option('请选择','');
for (i=0; i<sbulist.length; i++){
if (sbulist[i][0] == locationid){
document.myform.ClassList_2.options[document.myform.ClassList_2.length] = new Option(sbulist[i][2],sbulist[i][1]);
}
}
}

function checked2(locationid)
{
document.myform.ClassList_3.length=0;
document.myform.ClassList_3.options[0]=new Option('请选择','');
for (i=0; i<sbulist.length; i++){
if (sbulist[i][0] == locationid){
document.myform.ClassList_3.options[document.myform.ClassList_3.length] = new Option(sbulist[i][2],sbulist[i][1]);
}
}
}
</script>
<select name="ClassList_1" id="ClassList_1" style="width:250px; margin:2px 0;" onchange="checked1(this.value)">
<option value="">请选择</option>
<?php
//require("../include/Conn.php");
$rs="select * from proclasstree where ParentsID=0";
$res=mysql_query($rs,$link);
$nu=mysql_num_rows($res);
for($i=0;$i<$nu;$i++)
{
$rw=mysql_fetch_array($res);
echo"<option value='".$rw["ID"]."'>".$rw["ClassName"]."</option>";
}
?>
</select><br/>
<select name="ClassList_2" id="ClassList_2" style="width:250px; margin:2px 0;"onchange="checked2(this.value)">
<option value="">请选择</option>

</select>
<br/>
<select name="ClassList_3" id="ClassList_3" style="width:250px; margin:2px 0;">
<option value="">请选择</option>

</select>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: