<html>
<head>
<title>二级联动表单</title>
<script language="javascript">
//下面一行(仅仅一行)的内容由数据库输出 var strs='原料部 外检员 料场管理员 上垛管理员|总务部 网络管理员 总务主管 保安班长 后勤主管 |制浆车间 安全员 设备员 技术员';
//上面这一行从数据库里面提取,使用ASP应该非常简单,比如:
<%
'-----------------------------部门表SQL语句--------------------------------------
set rs_bm=server.createobject("adodb.recordset")
sql_bm="SELECT * from bumen where bm_yincang is null order by bm_name asc"
rs_bm.open sql_bm,conn,1,3
%>
<%
response.write "var strs='"
do while not rs_bm.EOF'用循环显示库中所有部门开始
%>
<%="|"&rs_bm("bm_name")&" "%>
<%
'--------岗位表SQL语句-------------------
set rs_gw=server.createobject("adodb.recordset")
sql_gw="SELECT * from gangwei where bm_name='"&rs_bm("bm_name")&"'"
rs_gw.open sql_gw,conn,1,3
do while not rs_gw.EOF '用循环显示库中所有岗位开始
%>
<%=rs_gw("gw_name")&" "%>
<%rs_gw.movenext
loop'循环显示所有岗位结束
rs_gw.movefirst'因为是循环内加循环,所以一定要用movefirst再次让循环开始
%>
<%
rs_bm.movenext
loop'循环显示所有部门结束
response.write "';"
%>
var opts=new Array();
//下面的代码利用数据库取出的strs变量,生成数组opts
var i,j,select_bm,select_gw;
select_bm=strs.split('|');
for (i=0;i<select_bm.length;i++){
opts[i]=new Array();
select_gw=select_bm[i].split(//s+/);
for (j=0;j<select_gw.length;j++){opts[i][j]=select_gw[j];}
}
//下面的函数初始化联动表单
function setup()
{
var select_bm=document.getElementById('id_select_bm');
with(select_bm){
length = 0;
for(i=0;i<opts.length;i++)
options[length]=new Option(opts[i][0],opts[i][0]);
}
select_bm_Changed();
}
//下面的函数在改变系时改变专业
function select_bm_Changed(){
var select_bm=document.getElementById('id_select_bm').selectedIndex;
var select_gw=document.getElementById('id_select_gw');
with(select_gw){
length = 0;
for(i=1;i<opts[select_bm].length;i++)
options[length]=new Option(opts[select_bm][i],opts[select_bm][i]);
}
}
</script>
</head>
<body>
<form>
<Select NAME="select_bm" class="input_1" id="id_select_bm" onChange="select_bm_Changed();">
</Select>
<Select NAME="select_gw" class="input_1" id="id_select_gw">
</Select>
</form>
<!--js初始化函数-->
<SCRIPT language="javascript">
setup()
</SCRIPT>
</body>
</html>