zoukankan      html  css  js  c++  java
  • ASP+JS三级连动下拉框


    <%
    '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
    %>

  • 相关阅读:
    Using Resource File on DotNet
    C++/CLI VS CSharp
    JIT VS NGen
    [Tip: disable vc intellisense]VS2008 VC Intelisense issue
    UVa 10891 Game of Sum(经典博弈区间DP)
    UVa 10723 Cyborg Genes(LCS变种)
    UVa 607 Scheduling Lectures(简单DP)
    UVa 10401 Injured Queen Problem(简单DP)
    UVa 10313 Pay the Price(类似数字分解DP)
    UVa 10635 Prince and Princess(LCS N*logN)
  • 原文地址:https://www.cnblogs.com/winner/p/417240.html
Copyright © 2011-2022 走看看