【转】asp二级联动的数据库版。

<!--#include file="include/conn.asp"-->
<script language = "javascript">
var j;
j=0;
goaler = new Array();
<%set rs=conn.execute("select * from SmallClass order by SmallClassID")
if rs.eof then%>
goaler[0] = new Array("无分类","","");
<%else
i=0
do while not rs.eof%>
goaler[<%=i%>] = new Array("<%=rs("SmallClassName")%>","<%=rs("BigClassID")%>","<%=rs("SmallClassID")%>");
<%rs.movenext
i=i+1
loop
end if
rs.close
%>
j=<%=i%>;

function changelocation(locationid)
{
document.goalerform.SmallClassID.length = 0;

var locationid=locationid;
var i;
for (i=0;i < j; i++)
{
if (goaler[i][1] == locationid)
{
document.goalerform.SmallClassID.options[document.goalerform.SmallClassID.length] = new Option(goaler[i][0], goaler[i][2]);
}
}

}
</script>

<form method="post" name="goalerform" action="">
<select name="BigClassID" onChange="changelocation(document.goalerform.BigClassID.options[document.goalerform.BigClassID.selectedIndex].value)" size="1">
<%set rs=conn.execute("select * from BigClass order by BigClassID")
if rs.eof then%>
<option selected value="">无一级分类</option>
<%else%>
<option selected value="">请选择一级分类</option>
<%do while not rs.eof%>
<option value="<%=rs("BigClassID")%>"><%=rs("BigClassName")%></option>
<%rs.movenext
loop
end if%>
</select>
<select name="SmallClassID">
<option selected value="">未指定一级分类</option>
</select>
<input type="submit" name="goaler" value="提交">
</form>


<%'测试取值
if request("goaler")<>"" then
response.write "BigClassID="&request("BigClassID")&"<BR>SmallClassID="&request("SmallClassID")
end if%>

--------==========================================================-----------------------

可能程序还有其它的同名的RECORDSET,为防止影响。可以改为

<%
SmallClassID=request.form("SmallClassID")
if SmallClassID<>"" then
set dansin=conn.execute("select titlename from News where Smallclassid="&SmallClassID
if not dansin.eof then
  do while not rs.eof
  response.write(dansin("titlename"))
  dansin.movenext
  loop
end if
dansin.close
else
response.write("SmallClassID值为空")
end if



  


<!-- #include virtual "/include/conn.asp" -->

<%
SmallClassID=request.form("SmallClassID")
if SmallClassID<>"" then
set rs=conn.execute("select page_name from News where Smallclassid=" SmallClassID)
if not rs.eof then
  do while not rs.eof
  response.write(rs("page_name"))
  rs.movenext
  loop
end if
else
response.write("SmallClassID值为空")
end if
rs.close
conn.close
%>

posted @ 2011-03-27 22:30  moretop  阅读(1288)  评论(0编辑  收藏  举报