ASP dynamic cascading menu code

Source: Internet
Author: User

JS script:
<%
Dim rs
Dim SQL
Dim count
Dim RS1
Dim sql1
SQL = "select * From region order by zoneid ASC"
Set rs = server. Createobject ("ADODB. recordset ")
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 (" regionname ") %> ", "<% = trim (RS (" zoneid ") %>", "<% = trim (RS (" regionid ") %> ");
<%
Count = count + 1
Rs. movenext
Loop
Rs. Close
Set rs = nothing
%>
Onecount = <% = count %>;

Function changelocation (zoneid)
{
Document. myform. region. Length = 0;

VaR zoneid = zoneid;
VaR I;
Document. myform. region. Options [0] = New Option ('-- region --','');
For (I = 0; I <onecount; I ++)
{
If (subcat [I] [1] = zoneid)
{
Document. myform. region. Options [document. myform. region. Length] = New Option (subcat [I] [0], subcat [I] [2]);
}
}

}
</SCRIPT>

Form Content:
<Table>
<Form>
<Tr>
<TD>
<SPAN class = "style1"> * </span> region:
<Select name = "zone" size = "1" id = "zone" onchange = "changelocation (document. myform. zone. options [document. myform. zone. selectedindex]. value) ">
<Option value = 0 selected> select </option>
<%

Sql1 = "select * From bigzone order by zonename ASC"
Set RS1 = server. Createobject ("ADODB. recordset ")
Rs1.open sql1, Conn, 1, 3
%>
<% While not rs1.eof %>
<Option value = "<% = RS1 (" zoneid ") %>"> <% = RS1 ("zonename") %> </option>
<% Rs1.movenext
Wend
Rs1.close
Set RS1 = nothing
%>
</SELECT> </TD>
<TD width = "20%"> <SPAN class = "style1"> * </span> region:
<Select name = "region" size = "1" id = "region">
<Option value = 0 selected> select </option>
</SELECT>
</Tr>
</Form>
</Table>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.