asp二级动态级联列表

两个select:BigClassName,SmallClassName,两个表BigClass,SmallClass
<%
'获取SmallTable数据
dim rs
dim sql
dim count
set rs=server.createobject("adodb.recordset")
sql = "select * from SmallClass order by SmallClassID asc"
rs.open sql,conn,1,1
%>
  <!--将SmallClass 里的相关字段放到数组里-->
  <script language = "JavaScript">
     var onecount;
  subcat = new Array();
    <%
    dim count
    count = 0
    rs
    %>
subcat[<%=count%>] = new Array("<%= trim(rs("SmallClassName"))%>","<%= trim(rs("BigClassName"))%>","<%= trim(rs("SmallClassName"))%>");
    <%
        count = count + 1
        rs.movenext
        loop
        rs.close
    %>
    //document.write(subcat)
  onecount=<%=count%>;
  <!--当一个select发生变化时,根据变化的locationid(selected)栏目去数组里查找,如果一样的话,就将该数组元素放到第二个select里 -->
 function changelocation(locationid)
    {
    document.myform.SmallClassName.length = 1;
    var locationid=locationid;
    var i;
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == locationid)
            {
                document.myform.SmallClassName.options[document.myform.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
            }        
        }
    }    
</script>

<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="862" align="center" valign="top"> <b><br>
      </b>
<form method="POST" name="myform" action="ProductSave.asp?action=add" target="_self">
        <table width="650" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
          <tr align="center">
            <td class="tdbg"> <table width="100%" border="0" cellpadding="0" cellspacing="0"  style="border:1px #009999 solid">
                <tr>
                  <td class="back_southidc" height="22" colspan="3" align="right" bgcolor="#D7E1FB"><div align="center"><strong>数据库支持的二级联动asp+js代码</strong>< /div></td>
                </tr>
                <tr>
                  <td width="159" height="30" align="right" valign="bottom" bgcolor="#F7F7F7" style="border-top:1px #009999 solid">产品类别</td>
                  <td width="445" colspan="2" valign="bottom" bgcolor="#F7F7F7" style="border-top:1px #009999 solid"> <strong>
                    <%
        sql = "select * from BigClass"
        rs.open sql,conn,1,1
        if rs.eof and rs.bof then
            response.write "没有分类"
        else
        %>
                    <select name="BigClassName" onChange="changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)" size="1">
                      <option selected value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>
            <%
            rs.movenext
            do while not rs.eof
            %>
                      <option value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>
                      <%
                rs.movenext
            loop
        end if
        rs.close
            %>
                    </select>
                    <select name="SmallClassName">
                      <option value="" selected>请选择小类</option>
   <select name="SmallClassName" style="width:120px" >
   </select>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值