求助:ASP二级联动如何改成三级联动..不断更新分数
我修改的老是不对.大家帮个忙..<scriptlanguage="JavaScript">varonecount;subcat=newArray();<%count=0d...
我修改的老是不对.大家帮个忙..
<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
dim SSclass
SSclass=rs("SmallClassName")
rs.movenext
if not(rs.eof and rs.bof) then
%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
do while not rs.eof%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
<select name="SSmallClassName">
<option value="" selected>不指定小小类</option>
<%
sql="select * from SSmallClass where SmallClassName='" & SSclass & "'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
%>
<option value="<%=rs("SSmallClassName")%>"><%=rs("SSmallClassName")%></option>
<%
do while not rs.eof%>
<option value="<%=rs("SSmallClassName")%>"><%=rs("SSmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
汗..你那个我改了..不行.我这个还关系到增加保存到数据库大体的一改动都需要改了.
如下三个表
BigClass
BigClassID BigClassName
SmallClass
SmallClassID SmallClassName BigClassName
SSmallClass
SSmallClassID SSmallClassName SmallClassName BigClassName 展开
<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
dim SSclass
SSclass=rs("SmallClassName")
rs.movenext
if not(rs.eof and rs.bof) then
%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
do while not rs.eof%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
<select name="SSmallClassName">
<option value="" selected>不指定小小类</option>
<%
sql="select * from SSmallClass where SmallClassName='" & SSclass & "'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
%>
<option value="<%=rs("SSmallClassName")%>"><%=rs("SSmallClassName")%></option>
<%
do while not rs.eof%>
<option value="<%=rs("SSmallClassName")%>"><%=rs("SSmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
汗..你那个我改了..不行.我这个还关系到增加保存到数据库大体的一改动都需要改了.
如下三个表
BigClass
BigClassID BigClassName
SmallClass
SmallClassID SmallClassName BigClassName
SSmallClass
SSmallClassID SSmallClassName SmallClassName BigClassName 展开
展开全部
根据这个修改试试
<!--#include file="edu_inc/conn.asp"-->
<%
dim cid,coid
cid = request("cid") 'cid 大类id
coid = request("coid") 'coid 中类id
set rs=server.createobject("adodb.recordset")
sql = "select * from edu_c" '表一 大类表
rs.open sql,conn,1,1
strOption1 = "<option value='' selected ></option>"
do while not rs.eof
if cstr(rs("id")) = cstr(cid) then
strOption1 = strOption1 & "<option value='" & rs("id") & "' selected>" & rs("c_name") & "</option>"
else
strOption1 = strOption1 & "<option value='" & rs("id") & "'>" & rs("c_name") & "</option>"
end if
rs.movenext
&nbs
p; loop
rs.close
if cid <> "" then
sql = "select * from edu_co where c_id=" & cid '表二 中类表 bid==表一中的id
rs.open sql,conn,1,1
strOption2 = "<option value='' selected >不指定小类</option>"
do while not rs.eof
if cstr(rs("id")) = cstr(coid) then
strOption2 = strOption2 & "<option value='" & rs("id") & "' selected>" & rs("co_name") & "</option>"
else
strOption2 = strOption2 & "<option value='" & rs("id") & "'>" & rs("co_name") & "</option>"
&nbs
p; end if
rs.movenext
loop
rs.close
end if
if coid <> "" then
sql = "select * from edu_s where co_id= " & coid '表三 小类表 mid==表二的id
rs.open sql,conn,1,1
strOption3 = "<option value='' selected >不指定小小类</option>"
while not rs.eof
if cstr(rs("id")) = cstr(sid) then
strOption3 = strOption3 & "<option value='" & rs("id") & "' selected>" & rs("s_name") & "</option>"
else
strOption3 = strOption3 & "<option
value='" & rs("id") & "'>" & rs("s_name") & "</option>"
end if
rs.movenext
wend
rs.close
end if
%>
<select onChange="changeb(this.value)" name="cid"><%=strOption1%></select>
<select onChange="change(this.value)" name="coid"><%=strOption2%></select>
<select name="sid"><%=strOption3%></select>
<script language="javascript">
<!--
function changeb(cid){
location.assign("three.asp?action=s_s&cid=" + cid);
}
function change(coid){
location.assign("three.asp?action=s_s&cid=<%=cid%>&coid=" + coid);
}
-->
</script>
<!--#include file="edu_inc/conn.asp"-->
<%
dim cid,coid
cid = request("cid") 'cid 大类id
coid = request("coid") 'coid 中类id
set rs=server.createobject("adodb.recordset")
sql = "select * from edu_c" '表一 大类表
rs.open sql,conn,1,1
strOption1 = "<option value='' selected ></option>"
do while not rs.eof
if cstr(rs("id")) = cstr(cid) then
strOption1 = strOption1 & "<option value='" & rs("id") & "' selected>" & rs("c_name") & "</option>"
else
strOption1 = strOption1 & "<option value='" & rs("id") & "'>" & rs("c_name") & "</option>"
end if
rs.movenext
&nbs
p; loop
rs.close
if cid <> "" then
sql = "select * from edu_co where c_id=" & cid '表二 中类表 bid==表一中的id
rs.open sql,conn,1,1
strOption2 = "<option value='' selected >不指定小类</option>"
do while not rs.eof
if cstr(rs("id")) = cstr(coid) then
strOption2 = strOption2 & "<option value='" & rs("id") & "' selected>" & rs("co_name") & "</option>"
else
strOption2 = strOption2 & "<option value='" & rs("id") & "'>" & rs("co_name") & "</option>"
&nbs
p; end if
rs.movenext
loop
rs.close
end if
if coid <> "" then
sql = "select * from edu_s where co_id= " & coid '表三 小类表 mid==表二的id
rs.open sql,conn,1,1
strOption3 = "<option value='' selected >不指定小小类</option>"
while not rs.eof
if cstr(rs("id")) = cstr(sid) then
strOption3 = strOption3 & "<option value='" & rs("id") & "' selected>" & rs("s_name") & "</option>"
else
strOption3 = strOption3 & "<option
value='" & rs("id") & "'>" & rs("s_name") & "</option>"
end if
rs.movenext
wend
rs.close
end if
%>
<select onChange="changeb(this.value)" name="cid"><%=strOption1%></select>
<select onChange="change(this.value)" name="coid"><%=strOption2%></select>
<select name="sid"><%=strOption3%></select>
<script language="javascript">
<!--
function changeb(cid){
location.assign("three.asp?action=s_s&cid=" + cid);
}
function change(coid){
location.assign("three.asp?action=s_s&cid=<%=cid%>&coid=" + coid);
}
-->
</script>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%
set rs=server.CreateObject("adodb.recordset")
sq="select * from BigClass"
rs.open sq,conn,1,1
%>
<select name="class1" onChange="changeclass2();changeclass3()">
<option value="" selected>选择大类</option>
<%
while not rs.eof
%>
<option value="<%=rs("BigClassName")%>"><%=rs("BigClassName")
%>
</option>
<%
rs.movenext
wend
rs.close
%>
</select>
<select name="class2" onChange="changeclass3()">
<option value="" selected>选择小类</option>
</select>
<select name="class3">
<option value="" selected>选择子类</option>
</select>
<%
sql="select * from SmallClass"
rs.open sql,conn,1,1
num=rs.recordcount
str=""
for i=1 to rs.recordcount
str=str&rs("BigClassName")&"-"&rs("SmallClassName")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<%
sql="select * from SSmallClass"
rs.open sql,conn,1,1
num2=rs.recordcount
str2=""
for i=1 to rs.recordcount
str2=str2&rs("SmallClassName")&"-"&rs("SSmallClassName")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<!--下面是实现动态改变下一级菜单的脚本代码-->
<script LANGUAGE="javascript">
arr="<%=str%>".split(",");
a=arr.length
ar=new Array()
for (i=0;i<a;i++){
ar[i]=arr[i].split("-");
}
onecount=ar.length;
arr2="<%=str2%>".split(",");
a2=arr2.length
ar2=new Array()
for (i=0;i<a2;i++){
ar2[i]=arr2[i].split("-");
}
onecount2=ar2.length;
function changeclass2() {
document.myform.class2.length=0
lid=myform.class1.value;
for (i=0;i<onecount;i++) {
if (ar[i][0] == lid) {
document.myform.class2.options.add(new Option(ar[i][1], ar[i][1]));
}
}
}
function changeclass3() {
document.myform.class3.length=0
lid2=myform.class2.value;
for (i=0;i<onecount2;i++) {
if (ar2[i][0] == lid2) {
document.myform.class3.options.add(new Option(ar2[i][1], ar2[i][1]));
}
}
}
</script>
改成这个联动可以了..但是保存不到数据库中..
set rs=server.CreateObject("adodb.recordset")
sq="select * from BigClass"
rs.open sq,conn,1,1
%>
<select name="class1" onChange="changeclass2();changeclass3()">
<option value="" selected>选择大类</option>
<%
while not rs.eof
%>
<option value="<%=rs("BigClassName")%>"><%=rs("BigClassName")
%>
</option>
<%
rs.movenext
wend
rs.close
%>
</select>
<select name="class2" onChange="changeclass3()">
<option value="" selected>选择小类</option>
</select>
<select name="class3">
<option value="" selected>选择子类</option>
</select>
<%
sql="select * from SmallClass"
rs.open sql,conn,1,1
num=rs.recordcount
str=""
for i=1 to rs.recordcount
str=str&rs("BigClassName")&"-"&rs("SmallClassName")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<%
sql="select * from SSmallClass"
rs.open sql,conn,1,1
num2=rs.recordcount
str2=""
for i=1 to rs.recordcount
str2=str2&rs("SmallClassName")&"-"&rs("SSmallClassName")&","
if rs.eof then exit for
rs.movenext
next
rs.close
%>
<!--下面是实现动态改变下一级菜单的脚本代码-->
<script LANGUAGE="javascript">
arr="<%=str%>".split(",");
a=arr.length
ar=new Array()
for (i=0;i<a;i++){
ar[i]=arr[i].split("-");
}
onecount=ar.length;
arr2="<%=str2%>".split(",");
a2=arr2.length
ar2=new Array()
for (i=0;i<a2;i++){
ar2[i]=arr2[i].split("-");
}
onecount2=ar2.length;
function changeclass2() {
document.myform.class2.length=0
lid=myform.class1.value;
for (i=0;i<onecount;i++) {
if (ar[i][0] == lid) {
document.myform.class2.options.add(new Option(ar[i][1], ar[i][1]));
}
}
}
function changeclass3() {
document.myform.class3.length=0
lid2=myform.class2.value;
for (i=0;i<onecount2;i++) {
if (ar2[i][0] == lid2) {
document.myform.class3.options.add(new Option(ar2[i][1], ar2[i][1]));
}
}
}
</script>
改成这个联动可以了..但是保存不到数据库中..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询