我用过的二级联动分类:
表名分别为:
articlesaid
articlesbid
表名和字段根据需求自行修改!
<%
dim count
set rsn=server.createobject("adodb.recordset")
rsn.open "select * from [articlesbid] order by [row]",conn,1,1
%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rsn.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rsn("Nclass"))%>","<%= rsn("classid")%>","<%= rsn("Nclassid")%>");
<%
count = count + 1
rsn.movenext
loop
rsn.close
%>
onecount=<%=count%>;
function changelocation(locationid)
{
document.myform.Nclassid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{ //这句不是很理解
document.myform.Nclassid.options[document.myform.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
<%
rsn.open "select * from [articlesaid] order by [row]",conn,1,1
if rsn.eof and rsn.bof then
response.write "请先添加栏目。"
response.end
else%>
<select name="anclassid" size="1" id="anclassid" onChange="changelocation(document.myform.anclassid.options[document.myform.anclassid.selectedIndex].value)">
<option selected value="<%=rsn("classid")%>"><%=trim(rsn("class"))%></option>
<%dim selclass
selclass=rsn("classid")
rsn.movenext
do while not rsn.eof%>
<option value="<%=rsn("classid")%>"><%=trim(rsn("class"))%></option>
<%
rsn.movenext
loop
end if
rsn.close%>
</select>
<select name="Nclassid">
<%rsn.open "select * from [articlesbid] where [classid]="&selclass ,conn,1,1
if not(rsn.eof and rsn.bof) then%>
<option selected value="<%=rsn("Nclassid")%>"><%=trim(rsn("Nclass"))%></option>
<%rsn.movenext
do while not rsn.eof%>
<option value="<%=rsn("Nclassid")%>"><%=trim(rsn("Nclass"))%></option>
<% rsn.movenext
loop
end if
rsn.close
set rsn = nothing%>
</select>