关闭

asp二级动态级联列表

138人阅读 评论(0) 收藏 举报
两个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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:59288次
    • 积分:1226
    • 等级:
    • 排名:千里之外
    • 原创:64篇
    • 转载:32篇
    • 译文:0篇
    • 评论:1条
    文章分类
    最新评论
    工作流专家