Database Table Design
Field classid, classname, classtype, parentclassid
Classid category ID
Classname category name
Classtype = 1 top-level category
Classtype = 2 level 1 category
Classtype = 3 level 2 Classification
Parentclassid: the parent class classid. The parent class of the top class is 0 by default.
Script code
<%
SQL = "select * From bs_productclass where classtype = 2 order by classid ASC"
Set rs = conn.exe cute (SQL)
%>
<Script language = "JavaScript">
VaR onecount;
Onecount = 0;
Subcat = new array ();
<%
Count1 = 0
Do while not Rs. EOF
%>
Subcat [<% = count1 %>] = new array ("<% = trim (RS (" classname ") %> ", "<% = trim (RS (" parentclassid ") %>", "<% = trim (RS (" classid ") %> ");
<%
Count1 = count1 + 1
Rs. movenext
Loop
Rs. Close
Set rs = nothing
%>
Onecount = <% = count1 %>;
Function changelocation (classid1)
{
Document. myform. bigclassid. Length = 0;
VaR classid1 = classid1;
VaR I;
VaR OP1 = Document. createelement ("option ");
Document. myform. bigclassid. Options [0] = New Option ('= category name = ','');
For (I = 0; I <onecount; I ++)
{
If (subcat [I] [1] = classid1)
{
OP1 = New Option (subcat [I] [0], subcat [I] [2]);
Document. myform. bigclassid. Options. Add (OP1 );
}
}
}
</SCRIPT>
<% Sql2 = "select * From bs_productclass where classtype = 3 order by classid ASC"
Set rs2 = conn.exe cute (sql2)
%>
<Script language = "JavaScript">
VaR onecount2;
Onecount2 = 0;
Subcat2 = new array ();
<%
Count2 = 0
Do while not rs2.eof
%>
Subcat2 [<% = count2 %>] = new array ("<% = trim (rs2 (" classname ") %> ", "<% = trim (rs2 (" parentclassid ") %>", "<% = trim (rs2 (" classid ") %> ");
<%
Count2 = count2 + 1
Rs2.movenext
Loop
Rs2.close
Set rs2 = nothing
%>
Onecount2 = <% = count2 %>;
Function changelocation2 (classid2)
{
Document. myform. smallclassid. Length = 0;
VaR classid2 = classid2;
VaR J;
VaR OP2 = Document. createelement ("option ");
Document. myform. smallclassid. Options [0] = New Option ('= Name of the class to which it belongs = ','');
For (j = 0; j <onecount2; j ++)
{
If (subcat2 [J] [1] = classid2)
{
OP2 = New Option (subcat2 [J] [0], subcat2 [J] [2]);
Document. myform. smallclassid. Options. Add (OP2 );
}
}
}
</SCRIPT>
Call Code
<Form name = 'myform'>
<Select name = "topclassid" id = "topclassid" onchange = "changelocation (document. myform. topclassid. Options. Value)" size = "1">
<Option selected value = ""> select the top class </option>
<%
Sql1 = "select * From bs_productclass where classtype = 1 order by classid ASC"
Set RS1 = conn. Execute (sql1)
Do while not rs1.eof
%>
<Option value = "<% = trim (RS1 (" classid ") %>"> <% = trim (RS1 ("classname") %> </option>
<%
Rs1.movenext
Loop
Rs1.close
Set RS1 = nothing
Conn. Close
Set conn = nothing
%>
</SELECT>
Category
<Select name = "bigclassid" id = "bigclassid" onchange = "changelocation2 (document. myform. bigclassid. Options [This. Options. selectedindex]. Value)">
<Option selected value = "" >== all classes ==</option>
</SELECT>
Sub-category
<Select name = "smallclassid" id = "smallclassid" size = "1">
<Option selected value = "" >== all small classes ==</option>
</SELECT>
</Form>