ASP+JS三級連動下拉框

來源:互聯網
上載者:User

<%
'OK工作室 http://ok123.k989.com
'sort   一級分類表:sort_id,sort_name
'nsort  二級分類表:nsort_id,sort_id,nsort_name
'nnsort 三級分類表:nnsort_id,nsort_id,nnsort_name
%>
<!--#include file="conn.asp"-->
<%
dim count
set rs=server.createobject("adodb.recordset")
sql="select * from  nsort"
rs.open sql,conn,1,3
%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
        <%
        count = 0
        do while not rs.eof
        %>
subcat[<%=count%>] = new Array("<%= trim(rs("nsort_name"))%>","<%= trim(rs("sort_id"))%>","<%= trim(rs("nsort_id"))%>");
        <%
        count = count + 1
        rs.movenext
        loop
        rs.close
        %>
onecount=<%=count%>;

function changelocation(locationid)
    {
    document.form.nsort_id.length = 0;

    var locationid=locationid;
 document.form.nsort_id.options[0] = new Option('二級分類', '');
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)
            {
                document.form.nsort_id.options[document.form.nsort_id.length] = new Option(subcat[i][0], subcat[i][2]);
            }       
        }
       
    }   
</script>

<%
sql = "select * from nnsort"
rs.open sql,conn,1,1
%>
<script language = "javascript">
var onecount2;
onecount2=0;
subcat2 = new Array();
<%
count2 = 0
do while not rs.eof
%>
subcat2[<%=count2%>] = new Array("<%= trim(rs("nnsort_name"))%>","<%= trim(rs("nsort_id"))%>","<%= trim(rs("nnsort_id"))%>");
<%
count2 = count2 + 1
rs.movenext
loop
rs.close
%>
onecount2=<%=count2%>;

function changelocation2(locationid)
{
document.form.nnsort_id.length = 0;

var locationid=locationid;
var j;
document.form.nnsort_id.options[0] = new Option('三級分類','');
for (j=0;j < onecount2; j++)
{
if (subcat2[j][1] == locationid)
{
document.form.nnsort_id.options[document.form.nnsort_id.length] = new Option(subcat2[j][0], subcat2[j][2]);
}
}

}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS三級連動下拉框</title>
</head>

<body>
<form name="form" method="post" action="">
  <select name="sort_id" onChange="changelocation(document.form.sort_id.options[document.form.sort_id.selectedIndex].value);changelocation2(document.form.nsort_id.options[document.form.nsort_id.selectedIndex].value);">
    <option selected>一級分類</option>
 <%
  sql="select * from sort"
  rs.open sql,conn,1,1
  do while not rs.eof
  %>
  <option value="<%=rs("sort_id")%>"><%=rs("sort_name")%></option>
  <%
    rs.movenext
  loop
  rs.close
  %>
  </select>
  <select name="nsort_id" onChange="changelocation2(document.form.nsort_id.options[document.form.nsort_id.selectedIndex].value);">
    <option selected>二級分類</option>
  </select>
  <select name="nnsort_id">
    <option selected>三級分類</option>
  </select>
</form>
</body>
</html>
<%
set rs=nothing
conn.close
set conn=nothing
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.