ASP+JS三級聯動下拉式功能表[調用資料庫資料]

來源:互聯網
上載者:User

網上三級菜單多是多但是代碼都比較煩,我這個應該說還是比較直觀的:
'肯定先要串連資料庫了,不用說了
'資料庫結構
'類別1表名稱:a 欄位:ID,Name 說明:ID為主鍵是類別1的ID值,Name為類別1的名稱
'類別2表名稱:aa 欄位:ID,aID,Name 說明:ID為主鍵是類別2的ID值,aID為所屬類別1的ID值,Name為類別2的名稱
'類別3表名稱:aaa 欄位:ID,aID,aaID,Name 說明:ID為主鍵是類別3的ID值,aID為所屬類別1的ID值,aaID為所屬類別2的ID值,Name為類別3的名稱
=====test1.asp 你可以測試下,接收到的都是類別的ID值====
<%
response.write"1:"&Request.form("s1")&"<BR>"
response.write"2:"&Request.form("s2")&"<BR>"
response.write"3:"&Request.form("s3")&"<BR>"
%> 複製代碼 代碼如下:<!-- 三級聯動菜單 開始 -->
<script language="JavaScript">
<!--
<%
'二級資料儲存到數組
Dim count2,rsClass2,sqlClass2
set rsClass2=server.createobject("adodb.recordset")
sqlClass2="select * from aa"
rsClass2.open sqlClass2,conn,1,1
%>
var subval2 = new Array();
//數組結構:一級根值,二級根值,二級顯示值
<%
count2 = 0
do while not rsClass2.eof
%>
subval2[<%=count2%>] = new Array('<%=rsClass2("aID")%>','<%=rsClass2("ID")%>','<%=rsClass2("Name")%>')
<%
count2 = count2 + 1
rsClass2.movenext
loop
rsClass2.close
%>
<%
'三級資料儲存到數組
Dim count3,rsClass3,sqlClass3
set rsClass3=server.createobject("adodb.recordset")
sqlClass3="select * from aaa"
rsClass3.open sqlClass3,conn,1,1
%>
var subval3 = new Array();
//數組結構:二級根值,三級根值,三級顯示值
<%
count3 = 0
do while not rsClass3.eof
%>
subval3[<%=count3%>] = new Array('<%=rsClass3("aaID")%>','<%=rsClass3("ID")%>','<%=rsClass3("Name")%>')
<%
count3 = count3 + 1
rsClass3.movenext
loop
rsClass3.close
%>
function changeselect1(locationid)
{
document.form1.s2.length = 0;
document.form1.s2.options[0] = new Option('==請選擇類別==','');
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==請選擇專題==','');
for (i=0; i<subval2.length; i++)
{
if (subval2[i][0] == locationid)
{document.form1.s2.options[document.form1.s2.length] = new Option(subval2[i][2],subval2[i][1]);}
}
}
function changeselect2(locationid)
{
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==請選擇專題==','');
for (i=0; i<subval3.length; i++)
{
if (subval3[i][0] == locationid)
{document.form1.s3.options[document.form1.s3.length] = new Option(subval3[i][2],subval3[i][1]);}
}
}
//-->
</script>
<form name="form1" method="post" action="test1.asp">
三級聯動:
<%
Dim count1,rsClass1,sqlClass1
set rsClass1=server.createobject("adodb.recordset")
sqlClass1="select * from a"
rsClass1.open sqlClass1,conn,1,1
%>
<select name="s1" onChange="changeselect1(this.value)">
<option>==請選擇頻道==</option>
<%
count1 = 0
do while not rsClass1.eof
response.write"<option value="&rsClass1("ID")&">"&rsClass1("Name")&"</option>"
count1 = count1 + 1
rsClass1.movenext
loop
rsClass1.close
%>
</select>
<select name="s2" onChange="changeselect2(this.value)">
<option>==請選擇類別==</option>
</select>
<select name="s3">
<option>==請選擇專題==</option>
</select>
<input type="submit" name="Submit" value="提交"></form>
<!-- 三級聯動菜單 結束 -->
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.