asp兩級聯動菜單代碼

來源:互聯網
上載者:User
<form name=myform method=post action=''>
                    <tr bgcolor="#F6FAFD"><%
  set rs = server.CreateObject("adodb.recordset")
  rs.open "select categoryid,category from category where first=1 order by categoryorder",conn,1,1
  if rs.eof and rs.bof then
  response.Write "<tr><td align=center>還沒有商品分類</td></tr>"
  else
   %>
                      <td height="30" colspan="2" align="center"><span class="style16">
                        <select name="categoryid" onChange="changelocation(document.myform.categoryid.options[document.myform.categoryid.selectedIndex].value)">
                          <option value="----品牌----" selected>----品牌----</option>
                         
  <% do while not rs.eof %>
   <option value="<%=trim(rs("categoryid"))%>"><%=trim(rs("category"))%></option>
                         
   <%
        rs.movenext
        loop
end if 
        rs.close
        set rs = nothing
        'conn.Close
        'set conn = nothing
%>
        </select>
                        
                      </span></td>
                    </tr>

                    <tr bgcolor="#F6FAFD">
                      <td height="30" colspan="2" align="center"><span class="style16">
                       <select name="sortsid">
             <option selected value>---請選分類---</option>

  
              </select>
                      </span></td>
                    </tr></form>
<SCRIPT language="javascript">
var onecount;
onecount=0;
subcat = new Array();
        <%
        count = 0
        do while not rs1.eof 
        %>
subcat[<%=count%>] = new Array("<%= trim(rs1("sorts"))%>","<%= trim(rs1("categoryid"))%>","<%= trim(rs1("sortsid"))%>");
        <%
        count = count + 1
        rs1.movenext
        loop
        rs1.close
        %>
onecount=<%=count%>;

function changelocation(locationid)
    ...{
     document.myform.sortsid.length = 0; 

      var locationid=locationid;
     var i;

     for (i=0;i < onecount; i++)
        ...{
            if (subcat[i][1] == locationid)
            ...{ 
                document.myform.sortsid.options[document.myform.sortsid.length] = new Option(subcat[i][0], subcat[i][2]);
            }        
        }  
    }    
</SCRIPT> 

 注意:1、數組存放順序(哪個是與一級菜單的值) 2、數組中的值要用雙引號""引起來  3、javascript:new Option(text, value)

相關文章

聯繫我們

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