asp:下拉菜单连接数据库问题
<%sql="selectBigClassNamefromBigClass"rs.opensql,conn,1,1ifrs.eofandrs.bofthenrespons...
<%
sql = "select BigClassName from BigClass"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "请选择?"
else
%>
<strong>
<select name="BigClassName" id= "bigclassname""size="1" onChange="changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)">
<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>
</strong>
<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
%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<% rs.movenext
do while not rs.eof%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
这是代码,二级下拉菜单,第一个下拉菜单选择大类(BigClassName)
然后 第二个菜单显示对应的小类(SmallClassname)
表名:BigClass
字段:BigClassName
我想在第一个下拉菜单中现实 BigClassName 的内容
现在的情况是什么第一个下拉菜单显示为空。。。。
不知道哪里出了问题。。
望指正。 展开
sql = "select BigClassName from BigClass"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "请选择?"
else
%>
<strong>
<select name="BigClassName" id= "bigclassname""size="1" onChange="changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)">
<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>
</strong>
<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
%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<% rs.movenext
do while not rs.eof%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
这是代码,二级下拉菜单,第一个下拉菜单选择大类(BigClassName)
然后 第二个菜单显示对应的小类(SmallClassname)
表名:BigClass
字段:BigClassName
我想在第一个下拉菜单中现实 BigClassName 的内容
现在的情况是什么第一个下拉菜单显示为空。。。。
不知道哪里出了问题。。
望指正。 展开
展开全部
下面是我改的一个网上的下拉菜单
希望帮得上你
HPMenu.asp
<style type="text/css">
body, td
{
font-family: 宋体;
font-size: 12px;
}
</style>
<script language="javascript" src="hpmenu.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!--
//屏蔽js错误
function ResumeError() {
return true;
}
window.onerror = ResumeError;
// -->
//alert(document.form1.meun1.value);
</SCRIPT>
<body onLoad="javascript:ResumeError()">
<form name="form1" method="post" action="HPMenuI.asp">
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="F1F1F1">
<td height="24" colspan="2" align="center"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="12%" height="24" align="center">洲:</td>
<td>
<%
a1=""
b1=""
c1=""
connstr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath("../hpmenu11/ajax_data.mdb")
set conn=Server.createobject("adodb.connection")
conn.open connstr
set rs1 = Server.CreateObject("ADODB.Recordset")
sql1="select * from a1"
rs1.open sql1,conn,1,1
while not rs1.eof
a1=a1&rs1("a1")&"|||"
rs1.movenext
wend
rs1.close
sql1="select * from b1 a,a1 b where a.aid=b.aid"
rs1.open sql1,conn,1,1
while not rs1.eof
b1=b1&rs1("a1")&"###"&rs1("b1")
rs1.movenext
if not rs1.eof then
b1=b1&"|||"
end if
wend
rs1.close
sql1="select * from c1,b1 where c1.bid=b1.bid"
rs1.open sql1,conn,1,1
while not rs1.eof
c1=c1&rs1("b1")&"###"&rs1("c1")
rs1.movenext
if not rs1.eof then
c1=c1&"|||"
end if
wend
%>
<input name="m1" id="m1" type="hidden" value="<%=a1%>">
<input name="m2" id="m2" type="hidden" value="<%=b1%>">
<input name="m3" id="m3" type="hidden" value="<%=c1%>">
<select name="zhou" id="zhou" onChange="Menu(this.form,1);">
<option value="" selected>-----请选择-----</option>
<%
set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from a1"
rs.open sql,conn,1,1
while not rs.eof
%>
<option value='<%=rs("a1")%>'><%=rs("a1")%></option>
<%rs.movenext
wend%>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="24" align="center">国:</td>
<td><select name="guo" id="select" onChange="Menu(this.form,2);">
<option value="" selected>-----请选择-----</option>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="24" align="center">市:</td>
<td><select name="shi" id="select2" onChange="Menu(this.form,3);">
<option value="" selected>-----请选择-----</option>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="24" align="center">区:</td>
<td><select name="qu" id="select3">
<option value="" selected>-----请选择-----</option>
</select></td>
</tr>
<tr bgcolor="F1F1F1">
<td height="24" colspan="2" align="center"><input name="submit" type="submit" value="提交"></td>
</tr>
</table>
<br>
<script language="javascript">
Menu(eval("document.form1"),1)
</script>
</form>
</body>
HPMenu.js
function Menu(theform,menuid) {
//////////////////////////////////连接数据库///////////////////////////////////
/*var xDOM = new ActiveXObject("MSXML.DOMDocument");
var rsXML = new ActiveXObject("ADODB.Recordset");
var sSQL, sConn;
sSQL = "Select * FROM [a1]";
sConn= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E://hpmenu11/ajax_data.mdb";
rsXML.Open(sSQL, sConn);
rsXML.Save(xDOM, 1);*/
/*---------------------------------------------------------------------------*\
* 1.变量定义 *
\*---------------------------------------------------------------------------*/
//定义菜单级别MenuClass,菜单长度数组MenuLenArr,菜单名称数组MenuArr,下级菜单数组SubMenuArr,菜单ID数组MenuIdArr
var MenuClass,MenuLenArr,MenuArr,SubMenuArr,MenuIdArr;
//定义分隔符:splitchar1,splitchar2
var splitchar1,splitchar2;
//定义临时数组,子数组,数组长度,
var arr,subarr,arrlen;
/*---------------------------------------------------------------------------*\
* 2.变量赋值 *
\*---------------------------------------------------------------------------*/
MenuArr=new Array();
MenuLenArr=new Array();
SubMenuArr=new Array();
MenuIdArr=new Array();
/*while(!rsXML.eof)
{
MenuArr[1]=MenuArr[1] + rsXML("a1") + "|||";
rsXML.MoveNext
}*/
MenuArr[1]=document.form1.m1.value; //洲名|||...
//alert(MenuArr[1]);
/*sSQL = "Select * FROM [b1]";
rsXML.Close
rsXML.Open(sSQL, sConn);
rsXML.Save(xDOM, 1);
MenuArr[2]=""
while(!rsXML.eof)
{*/
/* MenuArr[2]=MenuArr[2]*//* + "|||" *//*+ rsXML("aid") + "###" + rsXML("b1")*/ /*+ "|||"*///;
/*rsXML.MoveNext
if(!rsXML.eof)
{
MenuArr[2]=MenuArr[2]+"|||"
}
}*/
MenuArr[2]=document.form1.m2.value; //洲名###国名|||...
/*sSQL = "Select * FROM [c1]";
rsXML.Close
rsXML.Open(sSQL, sConn);
rsXML.Save(xDOM, 1);
MenuArr[3]=""
while(!rsXML.eof)
{*/
/* MenuArr[3]=MenuArr[3]*/ /*+ "|||" *//*+ rsXML("bid") + "###" + rsXML("c1") + "|||";*/
/*rsXML.MoveNext
}*/
MenuArr[3]=document.form1.m3.value; //国名###城市名|||...
/* sSQL = "Select * FROM [c1]";
rsXML.Close
rsXML.Open(sSQL, sConn);
rsXML.Save(xDOM, 1);
for(i=0;i<rsXML.fields.Count;i++)
{
MenuArr[4]=MenuArr[4] + rsXML("bid") + "###" + rsXML("c1") + "|||";
}*/
MenuArr[4]="北京###朝阳区|||上海###徐汇区|||广州###天河区|||纽约###曼哈顿区|||地狱###魔鬼"; //国名###城市名|||...
MenuIdArr[1]="zhou";
MenuIdArr[2]="guo";
MenuIdArr[3]="shi";
MenuIdArr[4]="qu";
MenuClass=4; //4级菜单
splitchar1="|||";
splitchar2="###";
/*---------------------------------------------------------------------------*\
* 3.生成数组 *
\*---------------------------------------------------------------------------*/
for(iii=1;iii<=MenuClass;iii++)
{
arr=MenuArr[iii].split(splitchar1);
len=arr.length;
subarr=new Array();
for (i=0;i<len;i++)
{
subarr[i]=arr[i].split(splitchar2);
}
len=subarr.length;
SubMenuArr[iii]=subarr;
MenuLenArr[iii]=len;
}
//============更改下级菜单======================
var self,submenu,thislen,thisarr;
//self本级菜单
//submenu子菜单
//theform:所在表单对象[type:object]
//menuid:本级菜单级别ID,如1级菜单则为1
self=eval("document."+theform.name+"."+MenuIdArr[menuid]);
submenu=eval("document."+theform.name+"."+MenuIdArr[menuid+1]);
thislen=MenuLenArr[menuid+1];
thisarr=SubMenuArr[menuid+1];
submenu.length=0;
submenu.options.add(new Option("-----请选择-----",""));
for (i=0;i<thislen;i++)
{
if (thisarr[i][0] == self.value)
{
submenu.options.add(new Option(thisarr[i][1],thisarr[i][1]));
}
}
submenu.options[0].selected=true;
//============更改下级以下菜单==============
var kkk;
for(kkk=menuid+2;kkk<=MenuClass;kkk++)
{
submenu=eval("document."+theform.name+"."+MenuIdArr[kkk]);
submenu.length=0;
submenu.options.add(new Option("-----请选择-----",""));
submenu.options[0].selected=true;
}
}
希望帮得上你
HPMenu.asp
<style type="text/css">
body, td
{
font-family: 宋体;
font-size: 12px;
}
</style>
<script language="javascript" src="hpmenu.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!--
//屏蔽js错误
function ResumeError() {
return true;
}
window.onerror = ResumeError;
// -->
//alert(document.form1.meun1.value);
</SCRIPT>
<body onLoad="javascript:ResumeError()">
<form name="form1" method="post" action="HPMenuI.asp">
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="F1F1F1">
<td height="24" colspan="2" align="center"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="12%" height="24" align="center">洲:</td>
<td>
<%
a1=""
b1=""
c1=""
connstr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath("../hpmenu11/ajax_data.mdb")
set conn=Server.createobject("adodb.connection")
conn.open connstr
set rs1 = Server.CreateObject("ADODB.Recordset")
sql1="select * from a1"
rs1.open sql1,conn,1,1
while not rs1.eof
a1=a1&rs1("a1")&"|||"
rs1.movenext
wend
rs1.close
sql1="select * from b1 a,a1 b where a.aid=b.aid"
rs1.open sql1,conn,1,1
while not rs1.eof
b1=b1&rs1("a1")&"###"&rs1("b1")
rs1.movenext
if not rs1.eof then
b1=b1&"|||"
end if
wend
rs1.close
sql1="select * from c1,b1 where c1.bid=b1.bid"
rs1.open sql1,conn,1,1
while not rs1.eof
c1=c1&rs1("b1")&"###"&rs1("c1")
rs1.movenext
if not rs1.eof then
c1=c1&"|||"
end if
wend
%>
<input name="m1" id="m1" type="hidden" value="<%=a1%>">
<input name="m2" id="m2" type="hidden" value="<%=b1%>">
<input name="m3" id="m3" type="hidden" value="<%=c1%>">
<select name="zhou" id="zhou" onChange="Menu(this.form,1);">
<option value="" selected>-----请选择-----</option>
<%
set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from a1"
rs.open sql,conn,1,1
while not rs.eof
%>
<option value='<%=rs("a1")%>'><%=rs("a1")%></option>
<%rs.movenext
wend%>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="24" align="center">国:</td>
<td><select name="guo" id="select" onChange="Menu(this.form,2);">
<option value="" selected>-----请选择-----</option>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="24" align="center">市:</td>
<td><select name="shi" id="select2" onChange="Menu(this.form,3);">
<option value="" selected>-----请选择-----</option>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="24" align="center">区:</td>
<td><select name="qu" id="select3">
<option value="" selected>-----请选择-----</option>
</select></td>
</tr>
<tr bgcolor="F1F1F1">
<td height="24" colspan="2" align="center"><input name="submit" type="submit" value="提交"></td>
</tr>
</table>
<br>
<script language="javascript">
Menu(eval("document.form1"),1)
</script>
</form>
</body>
HPMenu.js
function Menu(theform,menuid) {
//////////////////////////////////连接数据库///////////////////////////////////
/*var xDOM = new ActiveXObject("MSXML.DOMDocument");
var rsXML = new ActiveXObject("ADODB.Recordset");
var sSQL, sConn;
sSQL = "Select * FROM [a1]";
sConn= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E://hpmenu11/ajax_data.mdb";
rsXML.Open(sSQL, sConn);
rsXML.Save(xDOM, 1);*/
/*---------------------------------------------------------------------------*\
* 1.变量定义 *
\*---------------------------------------------------------------------------*/
//定义菜单级别MenuClass,菜单长度数组MenuLenArr,菜单名称数组MenuArr,下级菜单数组SubMenuArr,菜单ID数组MenuIdArr
var MenuClass,MenuLenArr,MenuArr,SubMenuArr,MenuIdArr;
//定义分隔符:splitchar1,splitchar2
var splitchar1,splitchar2;
//定义临时数组,子数组,数组长度,
var arr,subarr,arrlen;
/*---------------------------------------------------------------------------*\
* 2.变量赋值 *
\*---------------------------------------------------------------------------*/
MenuArr=new Array();
MenuLenArr=new Array();
SubMenuArr=new Array();
MenuIdArr=new Array();
/*while(!rsXML.eof)
{
MenuArr[1]=MenuArr[1] + rsXML("a1") + "|||";
rsXML.MoveNext
}*/
MenuArr[1]=document.form1.m1.value; //洲名|||...
//alert(MenuArr[1]);
/*sSQL = "Select * FROM [b1]";
rsXML.Close
rsXML.Open(sSQL, sConn);
rsXML.Save(xDOM, 1);
MenuArr[2]=""
while(!rsXML.eof)
{*/
/* MenuArr[2]=MenuArr[2]*//* + "|||" *//*+ rsXML("aid") + "###" + rsXML("b1")*/ /*+ "|||"*///;
/*rsXML.MoveNext
if(!rsXML.eof)
{
MenuArr[2]=MenuArr[2]+"|||"
}
}*/
MenuArr[2]=document.form1.m2.value; //洲名###国名|||...
/*sSQL = "Select * FROM [c1]";
rsXML.Close
rsXML.Open(sSQL, sConn);
rsXML.Save(xDOM, 1);
MenuArr[3]=""
while(!rsXML.eof)
{*/
/* MenuArr[3]=MenuArr[3]*/ /*+ "|||" *//*+ rsXML("bid") + "###" + rsXML("c1") + "|||";*/
/*rsXML.MoveNext
}*/
MenuArr[3]=document.form1.m3.value; //国名###城市名|||...
/* sSQL = "Select * FROM [c1]";
rsXML.Close
rsXML.Open(sSQL, sConn);
rsXML.Save(xDOM, 1);
for(i=0;i<rsXML.fields.Count;i++)
{
MenuArr[4]=MenuArr[4] + rsXML("bid") + "###" + rsXML("c1") + "|||";
}*/
MenuArr[4]="北京###朝阳区|||上海###徐汇区|||广州###天河区|||纽约###曼哈顿区|||地狱###魔鬼"; //国名###城市名|||...
MenuIdArr[1]="zhou";
MenuIdArr[2]="guo";
MenuIdArr[3]="shi";
MenuIdArr[4]="qu";
MenuClass=4; //4级菜单
splitchar1="|||";
splitchar2="###";
/*---------------------------------------------------------------------------*\
* 3.生成数组 *
\*---------------------------------------------------------------------------*/
for(iii=1;iii<=MenuClass;iii++)
{
arr=MenuArr[iii].split(splitchar1);
len=arr.length;
subarr=new Array();
for (i=0;i<len;i++)
{
subarr[i]=arr[i].split(splitchar2);
}
len=subarr.length;
SubMenuArr[iii]=subarr;
MenuLenArr[iii]=len;
}
//============更改下级菜单======================
var self,submenu,thislen,thisarr;
//self本级菜单
//submenu子菜单
//theform:所在表单对象[type:object]
//menuid:本级菜单级别ID,如1级菜单则为1
self=eval("document."+theform.name+"."+MenuIdArr[menuid]);
submenu=eval("document."+theform.name+"."+MenuIdArr[menuid+1]);
thislen=MenuLenArr[menuid+1];
thisarr=SubMenuArr[menuid+1];
submenu.length=0;
submenu.options.add(new Option("-----请选择-----",""));
for (i=0;i<thislen;i++)
{
if (thisarr[i][0] == self.value)
{
submenu.options.add(new Option(thisarr[i][1],thisarr[i][1]));
}
}
submenu.options[0].selected=true;
//============更改下级以下菜单==============
var kkk;
for(kkk=menuid+2;kkk<=MenuClass;kkk++)
{
submenu=eval("document."+theform.name+"."+MenuIdArr[kkk]);
submenu.length=0;
submenu.options.add(new Option("-----请选择-----",""));
submenu.options[0].selected=true;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
网易云信
2023-12-06 广告
2023-12-06 广告
UIkit是一套轻量级、模块化且易于使用的开源UI组件库,由YOOtheme团队开发。它提供了丰富的界面元素,包括按钮、表单、表格、对话框、滑块、下拉菜单、选项卡等等,适用于各种类型的网站和应用程序。UIkit还支持响应式设计,可以根据不同...
点击进入详情页
本回答由网易云信提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询