求2级联动数据显示
本人是asp新人,先编一下代码,遇到问题,求高手帮忙解决如何在第二个表中,将2级联动的数据显示。程序是:
<!--#include file="DBPATH/dbpath.asp" -->
<table width="778" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td valign="middle" bgcolor="#FFFFFF">
<div align="left">
<script language="JavaScript">
function addbig(){
document.all.a.style.display="block";
document.all.b.style.display="none";
document.all.c.style.display="none";
}
function addsmall(){
document.all.b.style.display="block";
document.all.a.style.display="none";
document.all.c.style.display="none";
}
function viewmenu(){
document.all.a.style.display="none";
document.all.b.style.display="none";
document.all.c.style.display="block";
}
</script>
<%
'从小类表中取出数据
set rs=server.CreateObject("adodb.recordset")
sql="select * from small_class "
rs.open sql,conn,1,1
%>
<script language="JavaScript">
var num;
//定义数组
var calArray=new Array();
<%
dim j
j=0
do while not rs.eof
%>
//将小类表中的所有相关记录存到数组calArray的对应元素中。
calArray[<%=j%>]=new Array("<%=rs("small_class_link")%>","<%=rs("small_class_name")%>","<%=rs("belongto_big_class")%>");
<%
j=j+1
rs.movenext
loop
rs.close
set rs=nothing
%>
//给num赋值为记录总数
num=<%=j%>
function givevalue(myvalue){
/*当选择大类列表的值不为空时首先清空小类下拉列表的所有项目。不然小类列表中的项目会叠加的。
同时也是初始化 options 的值为0 */
document.form3.small_class_select.length = 0;
//循环写出请求的大类所对应的小类。
for (i=0;i < num; i++)
{
if (calArray[i][2] == myvalue)
{
document.form3.small_class_select.options[document.form3.small_class_select.length] = new Option(calArray[i][1], calArray[i][0],"","");
/*定义新的Option对象并赋值。options的索引值从0开始。new Option对象有4个属性,对应分别是:文本串、value、defaultSelect、selected。在这里只用了第一个和第二个。*/
}
}
}
</script>
<script language="JavaScript">
function chk1(){
if (form1.big_class_name.value=="")
{
alert("请输入大类名称!");
form1.big_class_name.focus();
return false;
}
}
function chk2(){
if (form2.small_class_name.value=="")
{
alert("请输入小类名称!");
form2.small_class_name.focus();
return false;
}
}
</script>
</head>
<body background="background.jpg">
<%
dim rs,sql,noclass
select case request("action")
case "addbigclass"
addbigclass
case "addsmallclass"
addsmallclass
end select
%>
<div align="center"></div>
<table width="770" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" colspan="2" valign="top"> <div id="a" style="display:none">
<form name="form1" method="post" action="" onSubmit="return chk1()">
大类名称:
<input name="big_class_name" type="text" id="big_class_name" size="16">
<input type="submit" name="Submit" value=" 添 加 ">
</form>
</div>
<div id="b" style="display:none">
<form name="form2" method="post" action="" onSubmit="return chk2()">
选择大类后添加小类:
<select name="addselect">
<%
set rs=server.CreateObject("adodb.recordset")
sql="big_class"
rs.open sql,conn,1,1
if rs.eof or rs.bof then
%>
<option selected>还没有添加大类</option>
<%
else
do while not rs.eof
%>
<option value="<%=rs("big_class_id")%>"><%=trim(rs("big_class_name"))%></option>
<%
rs.movenext
loop
end if
rs.close
set rs=nothing
%>
</select>
小类名称:
<input name="small_class_name" type="text" id="small_class_name" size="16">
链接地址:
<input name="small_class_link" type="text" id="small_class_link" size="16">
<input type="submit" name="Submit2" value=" 添 加 ">
</form>
</div>
<div id="c" style="display:block">
<form name="form3" method="post" action="">
大类:
<select name="big_class_select" onChange="givevalue(document.form3.big_class_select.options[document.form3.big_class_select.selectedIndex].value)">
<%
dim firstid
set rs=server.CreateObject("adodb.recordset")
sql="select * from big_class order by big_class_id"
rs.open sql,conn,1,1
if rs.eof or rs.bof then
noclass=1
%>
<option selected>还没有添加大类</option>
<%
else
rs.movefirst
firstid=rs("big_class_id")
'在没有选择大类(页面刚载入)时要载入的大类。
%>
<option value="<%=rs("big_class_id")%>" selected><%=trim(rs("big_class_name"))%></option>
<%
rs.movenext
do while not rs.eof
%>
<option value="<%=rs("big_class_id")%>"><%=trim(rs("big_class_name"))%></option>
<%
rs.movenext
loop
end if
rs.close
set rs=nothing
%>
</select>
小类:
<select name="small_class_select" onChange="parent.ham.location.href=this.options[this.selectedIndex].value" >
<%if noclass=1 then%>
<option value="" selected>没有小类</option>
<%
else
'在没有选择大类(页面刚载入)时要载入的小类,要跟默认的大类对应。
set rs=server.CreateObject("adodb.recordset")
sql="select * from small_class where belongto_big_class="&firstid
rs.open sql,conn,1,1
if rs.eof or rs.bof then
%>
<option value="" selected>没有小类</option>
<%
else
do while not rs.eof
%>
<option value="<%=rs("small_class_link")%>"><%=trim(rs("small_class_name"))%></option>
<%
rs.movenext
loop
end if
rs.close
set rs=nothing
end if
%>
</select>
<a href="#" onClick="addbig()">添加大类</a>
<a href="#" onClick="addsmall()">添加小类</a>
</form>
</tr>
</table>
<%
sub addbigclass()
set rs=server.CreateObject("adodb.recordset")
sql="select * from big_class where big_class_name='"&trim(request("big_class_name"))&"'"
rs.open sql,conn,1,3
if not(rs.eof and rs.bof) then
response.Write("<script>alert('该大类已经存在!');</script>")
else
rs.addnew
rs("big_class_name")=trim(request("big_class_name"))
rs.update
response.Write("<script>alert('大类添加成功!');self.location='addgongju.asp?action=viewmenu';</script>")
end if
rs.close
set rs=nothing
end sub
sub addsmallclass()
set rs=server.CreateObject("adodb.recordset")
sql="select * from small_class where small_class_name='"&trim(request("small_class_name"))&"' and belongto_big_class="&request("addselect")
rs.open sql,conn,1,3
if not(rs.eof and rs.bof) then
response.Write("<script>alert('该小类已经存在!');</script>")
else
rs.addnew
rs("belongto_big_class")=request("addselect")
rs("small_class_name")=trim(request("small_class_name"))
rs("small_class_link")=trim(request("small_class_link"))
rs.update
response.Write("<script>alert('小类添加成功!');self.location='addgongju.asp?action=viewmenu';</script>")
end if
rs.close
set rs=nothing
end sub
conn.close
set conn=nothing
%>
</td>
</tr>
</table>
<html>
<head>
<title>物资计划上报</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="css/style.css">
</td>
</tr>
<form action="savedata.asp" method="POST" name="addnews">
<table width="900" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#336600">
<tr bgcolor="#FFFFFF">
<td width="61" height="30">
<div align="center">大类:</div>
</td>
<td height="30">
<div align="left">
<input name="sbdw" type="text" id="sbdw" size="12" maxlength="20">
</div>
</td>
<td width="84" height="30">
<div align="center">小类:</div>
</td>
<td height="30">
<div align="left">
<input type="text" name="ip" size="20" maxlength="12">
</div>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="61" height="30">
<div align="center">上报人:</div>
</td>
<td height="30">
<div align="left">
<input name="sbr" type="text" id="sbr" size="12" maxlength="20">
</div>
</td>
<td width="84" height="30">
<div align="center">上报日期:</div>
</td>
<td height="30">
<div align="left">
<input name="sbrq" type="text" id="sbrq2" value="<%=date()%>" size="20" maxlength="30">
<script>
function obtion(){
var obj = document.getElementById("big_class_select");
var objDis = document.getElementById("dis"); var va = obj.value;
objDis.value = va;
}
</script>
<input type="text" name="dis" id="dis" value="获取选中的值"/>
<%
dim a
a=dis.value
%>
<input type="text" name="name" id="name" value="<%=conn.execute("select big_class_name from big_class where big_class_id="&a&"")(0)%>">
<select name="inter" id="inter" onchange="obtion()">
<option value="武术">武术</option>
<option value="音乐" selected="selected">音乐</option>
<option value="美术">美术</option>
<option value="购物">购物</option>
</select>
</div>
</td>
</tr>
</table>
<table width="618" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="middle" align="center"> <div align="center">
<br>
</div>
</td>
</tr>
</table>
</form>
<p>
<form name="AllForm" method="post" action="savedata.asp">
<input type="hidden" name="sbdw">
<input type="hidden" name="xl">
<input type="hidden" name="big_class_name">
<input type="hidden" name="addselect">
<input type="hidden" name="small_class_name">
<input type="hidden" name="small_class_link">
<input type="hidden" name="big_class_select">
<input type="hidden" name="small_class_select">
</form>
<input type="button" name="Submit" value="提交" onclick="GetSubmitValue()">
</body>
</html>