您的位置:首页 > Web前端 > JavaScript

两种js动态三级联动下拉表单测试

2007-06-14 09:48 477 查看
<html>
<head>
<title>三级联动下拉表单测试一</title>
<!--=======连接IT网主数据库======-->
</head>
<body>
<form name="myform" method="post">
<%
set rs=server.CreateObject("adodb.recordset")
sq="select * from 一级表"
rs.open sq,conn,1,1
%>
<select name="class1" onChange="changeclass2();changeclass3()">
<option value="" selected>选择一级目录</option>
<%
while not rs.eof
%>
<option value="<%=rs("一级类")%>"><%=rs("一级类")
%>
</option>
<%
rs.movenext
wend
rs.close
%>
</select>
<select name="class2" onChange="changeclass3()">
<option value="" selected>选择二级目录</option>
</select>
<select name="class3">
<option value="" selected>选择三级目录</option>
</select>
<%
sql="select * from 二级表"
rs.open sql,conn,1,1
num=rs.recordcount
str=""
for i=1 to rs.recordcount
str=str&rs("一级类")&"-"&rs("二级类")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<%
sql="select * from 三级表"
rs.open sql,conn,1,1
num2=rs.recordcount
str2=""
for i=1 to rs.recordcount
str2=str2&rs("二级类")&"-"&rs("三级类")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<!--下面是实现动态改变下一级菜单的脚本代码-->
<script LANGUAGE="javascript">
arr="<%=str%>".split(",");
a=arr.length
ar=new Array()
for (i=0;i<a;i++){
ar[i]=arr[i].split("-");
}
onecount=ar.length;
arr2="<%=str2%>".split(",");
a2=arr2.length
ar2=new Array()
for (i=0;i<a2;i++){
ar2[i]=arr2[i].split("-");
}
onecount2=ar2.length;
function changeclass2() {
document.myform.class2.length=0
lid=myform.class1.value;
for (i=0;i<onecount;i++) {
if (ar[i][0] == lid) {
document.myform.class2.options.add(new Option(ar[i][1], ar[i][1]));
}
}
}
function changeclass3() {
document.myform.class3.length=0
lid2=myform.class2.value;
for (i=0;i<onecount2;i++) {
if (ar2[i][0] == lid2) {
document.myform.class3.options.add(new Option(ar2[i][1], ar2[i][1]));
}
}
}
</script>
</body>
</html>

Reqeust获取参数实现动态三级联动下拉表单

<!--#include file="conn.asp"-->
<%
dim cid,coid
cid = request("cid") 'cid 大类id
coid = request("coid") 'coid 中类id
set rs=server.createobject("adodb.recordset")
sql = "select * from PE_Area" '表一 大类表
rs.open sql,conn,1,1
strOption1 = "<option value='' selected >==请选择所属市==</option>"
do while not rs.eof
if cstr(rs("id")) = cstr(cid) then
strOption1 = strOption1 & "<option value='" & rs("id") & "' selected>" & rs("c_name") & "</option>"
else

strOption1 = strOption1 & "<option value='" & rs("id") & "'>" & rs("c_name") & "</option>"

end if
rs.movenext
loop

rs.close

if cid <> "" then
sql = "select * from PE_Area where c_id=" & cid '表二 中类表 bid==表一中的id

rs.open sql,conn,1,1
strOption2 = "<option value='' selected >==请选择所属县==</option>"

do while not rs.eof
if cstr(rs("id")) = cstr(coid) then
strOption2 = strOption2 & "<option value='" & rs("id") & "' selected>" & rs("co_name") & "</option>"
else
strOption2 = strOption2 & "<option value='" & rs("id") & "'>" & rs("co_name") & "</option>"
end if
rs.movenext
loop
rs.close
end if

if coid <> "" then
sql = "select * from PE_Area where co_id= " & coid '表三 小类表 mid==表二的id
rs.open sql,conn,1,1
strOption3 = "<option value='' selected >==请选择乡==</option>"
while not rs.eof
if cstr(rs("id")) = cstr(sid) then
strOption3 = strOption3 & "<option value='" & rs("id") & "' selected>" & rs("s_name") & "</option>"
else
strOption3 = strOption3 & "<option value='" & rs("id") & "'>" & rs("s_name") & "</option>"
end if

rs.movenext
wend
rs.close
end if

%>
<select onchange="changeb(this.value)" name="cid"><%=strOption1%></select>
<select onchange="change(this.value)" name="coid"><%=strOption2%></select>
<select name="sid"><%=strOption3%></select>
<script language="javascript">
<!--
function changeb(cid){
location.assign("three.asp?action=s_s&cid=" + cid);
}

function change(coid){
location.assign("three.asp?action=s_s&cid=<%=cid%>&coid=" + coid);
}
-->
</script>

上面给出的是三级联动菜单,四级,多级联动菜单的制作一一类推。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: