把数据读到JS中
<%
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]);
}
}
}
一级栏目:
二级栏目:
$Page_Split$
(补充)更改栏目时将数据库中栏目设为默认值:
<%dim rs1
set rs1=server.CreateObject("adodb.recordset")
rs1.open "select * from [articles] where id="&clng(cid),conn,1,1
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)">
<%do while not rsn.eof%>
<option value="<%=rsn("classid")%>" <%if rs1("classid")=rsn("classid") then%>selected<%end if%>><%=trim(rsn("class"))%></option>
<%rsn.movenext
loop
end if
rsn.close%>
</select>
<select name="Nclassid">
<%rsn.open "select * from [articlesbid] where classid="&rs1("classid") ,conn,1,1
do while not rsn.eof%>
<option value="<%=rsn("Nclassid")%>" <%if rs1("Nclassid")=rsn("Nclassid") then%>selected<%end if%>><%=rsn("Nclass")%></option>
<%rsn.movenext
loop
rsn.close
set rsn= nothing%>
</select>