- 论坛徽章:
- 0
|
借用了网友的代码,但只能实现单选,请问怎么才能实现多选?
代码如下
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>全动态二级联动下拉列表</title>
</head>
<body>
<?
/***********************************************
** 功 能:PHP+mysql实现二级级联下拉框
***********************************************/
//****************** 连接选择数据库 ***************
$link = mysql_connect("localhost", "root", "")
or die("Could not connect : " . mysql_error());
mysql_select_db("office") or die("Could not select database");
//******************提取部门信息******************
$sqlSel = "select * from bumen order by name ";
$result = mysql_query($sqlSel) or die("Query failed : " . mysql_error());
$forum_data = array();
while( $row = mysql_fetch_array($result) )
{
$forum_data[] = $row;
}
print_r ($forum_data);
mysql_free_result($result);
//**************获取用户信息**************
$sqlSel2 = "select * from user order by bumenid desc";
if( !($result2 = mysql_query($sqlSel2)) )
{
die('Could not query t_city list');
}
$forum_data2 = array();
while( $row2 = mysql_fetch_array($result2) )
{
$forum_data2[] = $row2;
}
mysql_free_result($result2);
?>
<!--************ JavaScript处理province--onChange *************-->
<script language = "JavaScript">
var onecount2;
subcat2 = new Array();
<?php
$num2 = count($forum_data2);
?>
onecount2=<? echo $num2; ?>;
<?
for($j=0;$j<$num2;$j++)
{
?>
subcat2[<? echo $j; ?>] = new Array("<? echo $forum_data2[$j]['bumen']; ?>","<? echo $forum_data2[$j]['bumenid']; ?>","<? echo $forum_data2[$j]['name']; ?>");
<?}?>
function changelocation(id)
{
document.myform.user.length = 0;
var id=id;
var j;
document.myform.user.options[0] = new Option('==选择发布人==','');
for (j=0;j < onecount2; j++)
{
if (subcat2[j][1] == id)
{
document.myform.user.options[document.myform.user.length] = new Option(subcat2[j][2], subcat2[j][0]);
}
}
}
</script>
<!--********************页面表单*************************-->
<form name="myform" method="post" action="test.php">
部门:<select name="bigClass" onChange="changelocation(document.myform.bigClass.options[document.myform.bigClass.selectedIndex].value)" size="1">
<option selected>请选择部门</option>
<?php
$num = count($forum_data);
for($i=0;$i<$num;$i++)
{
?>
<option value="<? echo $forum_data[$i]['id']; ?>"><? echo $forum_data[$i]['name']; ?></option>
<?
}
?>
</select>
<select name="user" multiple>
<option selected value="">==选择发布人==</option>
</select>
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html> |
|