二级联动菜单数据库版

来源:互联网 发布:百度云和阿里云哪个好 编辑:程序博客网 时间:2024/05/01 15:22

<form action="" method="post" name="form1" id="form1">
<%
Dim rdsClass
Dim sqlClass
Dim rdsChlCls
Dim sqlChlCls

set rdsClass = Server.CreateObject("ADODB.Recordset")
sqlClass = "select * from big_class Where State = 1 Order By ListNum"
rdsClass.Open sqlClass,Conn,1,1

response.write "<script language=""JavaScript"">"
'var x_array = new Array(初始化列表);
s = "var p_array = new Array(" + cstr(rdsClass.recordcount-1) + ");"
response.write s
s = "var p_array_id = new Array(" + cstr(rdsClass.recordcount-1) + ");"
response.write s
i = 0
while not rdsClass.eof
 set rdsChlCls = Server.CreateObject("ADODB.Recordset")
 sqlChlCls = "select * from Dat_class where RootID="&rdsClass("RootId")
 rdsChlCls.Open sqlChlCls,Conn,1,1
 
  if rdsChlCls.recordcount > 0 then

 s = "var p"+cstr(rdsClass("RootId"))+"_array = Array("
 s1 = "var p"+cstr(rdsClass("RootId"))+"_array_id = Array("
 while not rdsChlCls.eof
  if trim(rdsChlCls("CnName"))<>"" then
   a = rdsChlCls("CnName")
   s = s + """" + rdsChlCls("CnName") + """"
   s1 = s1 + """" + cstr(rdsChlCls("ClsId")) + """"
  end if
  rdsChlCls.movenext
  if not rdsChlCls.eof then
   if trim(rdsChlCls("CnName"))<>"" then
    s = s + ","
    s1 = s1 + ","
   end if
  end if
 wend
 s = s+ ");"
 s1 = s1+ ");"
 response.write s
 response.write s1
 
 response.write "p_array["+cstr(i)+"] = p"+cstr(rdsClass("RootId"))+"_array;"
 response.write "p_array_id["+cstr(i)+"] = p"+cstr(rdsClass("RootId"))+"_array_id;"
  end if
  i = i + 1
rdsClass.movenext
wend

response.write  "</script>"
%>
                              <script language="JavaScript">
<!--
        function setSort(s1,s2)
        {
                param=s1.selectedIndex-1;
                  if(param>=0)
                  {
                        s2.options.length=0;
                        for(i=0;i<p_array[param].length;i++)
                        {
                                s2.options.length++;
                                s2.options[i].text=p_array[param][i];
                                s2.options[i].value=p_array_id[param][i];
                        }
                  }else
                  {
                     s2.options.length=0;
                     s2.options.length++;
                     s2.options[0].text="请选择";
                     s2.options[0].value="";
                  }
        }
//-->
                              </script>
                              <select name="s1" onChange="setSort(this,this.form.s2);">
                                <option value="0" selected>--大类--</option>
                                <%
set rdsClass = Server.CreateObject("ADODB.Recordset")
sqlClass = "select * from big_class where State=1 order by listnum"
rdsClass.Open sqlClass,Conn,1,1
 while not rdsClass.eof
 %>
                                <option value="<%=rdsClass("RootId")%>"><%=rdsClass("CnName")%></option>
                                <%
 rdsClass.movenext
 wend
 rdsClass.close
 set rdsClass=nothing
  %>
                              </select>
                              <select name="s2">
                                <option value="0" selected>--小类--</option>
                              </select>
<form>