<form action="ProductSave.asp?action=add" method="POST" name="myform" onSubmit="return CheckForm();"><%
sql = "select * from BigClass"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "请先添加栏目。"
else
%>
<select name="BigClassName" onChange="changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)" size="1">
<option selected value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>
<%
dim selclass
selclass=rs("BigClassName")
rs.movenext
do while not rs.eof
%>
<option value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select><!--第一级代码--><select name="SmallClassName" >
<option value="" selected>不指定小类</option>
<%
sql="select * from SmallClass where BigClassName='" & selclass & "'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
dim selc
selc=rs("SmallClassName")
rs.movenext
do while not rs.eof%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select><!--第二级代码-->
<select name="SmallName">
<option value="" selected>不指定小类</option>
<%
sql="select * from SmallClass where BigClassName='" & selc & "'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
do while not rs.eof%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select><!--第三级代码-->现在情况是第一级改变,第二级会跟着改变,第二级选择后,第三级没改变,我知道第三级要改变应该需要一段JS代码的,可是我不会写,想请高手帮帮忙……写一段可行的代码并注解就最好了,目前我js方面还属于菜鸟级的对了,再贴上第一级的js代码:
<script language = "JavaScript">
var onecount;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("SmallClassName"))%>","<%= trim(rs("BigClassName"))%>","<%= trim(rs("SmallClassName"))%>");
<%
count = count + 1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;function changelocation(locationid)
{
document.myform.SmallClassName.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.SmallClassName.options[document.myform.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
sql = "select * from BigClass"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "请先添加栏目。"
else
%>
<select name="BigClassName" onChange="changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)" size="1">
<option selected value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>
<%
dim selclass
selclass=rs("BigClassName")
rs.movenext
do while not rs.eof
%>
<option value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select><!--第一级代码--><select name="SmallClassName" >
<option value="" selected>不指定小类</option>
<%
sql="select * from SmallClass where BigClassName='" & selclass & "'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
dim selc
selc=rs("SmallClassName")
rs.movenext
do while not rs.eof%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select><!--第二级代码-->
<select name="SmallName">
<option value="" selected>不指定小类</option>
<%
sql="select * from SmallClass where BigClassName='" & selc & "'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
do while not rs.eof%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select><!--第三级代码-->现在情况是第一级改变,第二级会跟着改变,第二级选择后,第三级没改变,我知道第三级要改变应该需要一段JS代码的,可是我不会写,想请高手帮帮忙……写一段可行的代码并注解就最好了,目前我js方面还属于菜鸟级的对了,再贴上第一级的js代码:
<script language = "JavaScript">
var onecount;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("SmallClassName"))%>","<%= trim(rs("BigClassName"))%>","<%= trim(rs("SmallClassName"))%>");
<%
count = count + 1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;function changelocation(locationid)
{
document.myform.SmallClassName.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.SmallClassName.options[document.myform.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
JS代码多复制一个并改成这个样子:
function changelocation1(locationid)
{
document.myform.SmallName.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.SmallName.options[document.myform.SmallName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
第二级加上:onChange="changelocation1(document.myform.SmallClassName.options[document.myform.SmallClassName.selectedIndex].value)"
这样就行了