自动生成二级联动菜单得问题
我想写一个能自动生成二级联动菜单的函数,可是调试了很久都不行,所以拿出来让大家帮忙看看,感激不尽啊!代码是这样的:
数据库名为exam
表名:section
字段一:section_id 自动增长的ID
字段二:section_name 即名称
字段三:parent_id 即该项的父ID(即所属ID)
字段四:type 类型(0表示一级菜单,1表示二级菜单)
<!--#include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>二级联动菜单</title>
</head>
<!------------------------------------------------------------------------------------------------------->
<script language="javascript">
function createlist(oneclass,twoclass)
{
document.writeln("function changeone(locationid)");
document.writeln("{document.two_list."&twoclass&".length=0;");
document.writeln("document.two_list."&twoclass&".options[0]=new Option('==选择专业==','');");
document.writeln("for(var i=0; i < ary.length ;i++)");
document.writeln("{if(ary[i][0] == locationid)");
document.writeln("{document.two_list."&twoclass&".options[document.two_list."&twoclass&".length]=new Option(ary[i][2],ary[i][1]);}");
document.writeln("}}}");
document.writeln("<select name="&oneclass&" onChange="changeone(this.value)"><option>==选择学院==</option>");
<%set rs_1=server.CreateObject("adodb.recordset")
sql_1="select * from section where type=0"
rs_1.open sql_1,conn,1,1
do while Not rs_1.eof %>
document.writeln("response.Write "<option value="&rs_1("section_id")&">"&rs_1("section_name")&"</option>"");
<%rs_1.movenext
loop
rs_1.close %>;
document.writeln("</select><select name="twoclass"><option>==选择专业==</option></select>");
<%set rs=server.CreateObject("adodb.recordset")
sql="select * from section where type=1"
rs.open sql,conn,1,1%>;
document.writeln("var ary = new Array();");
document.writeln("<%count=0%>");
document.writeln("<% do while not rs.eof %>");
document.writeln("ary[<%=count%>]=new Array('<%=rs("parent_id")%>','<%=rs("section_id")%>','<%=rs("section_name")%>');");
document.writeln("<% count=count + 1 %>");
document.writeln("<%rs.movenext%>");
document.writeln("<%loop%>");
document.writeln("<%rs.close %>");
document.writeln("conn.close");
document.writeln("set conn=nothing");
</script>
<body>
<form action="#" method="post" name="two_list">
<script language="javascript">
createlist("oneclass","twoclass");
</script>
</form>
</body>
</html>