asp二级联动列表,如何 同时传递多个参数呢?谢谢~

aerobic 2011-08-29 04:43:10

下面的代码,二级联动传递:BigClassName和SmallClassName。

请入如何同时传递 BigClassID和SmallClassID 呢?谢谢~

--------------------------------------------------------------

<%
dim rs
dim sql
dim count
set rs=server.createobject("adodb.recordset")
sql = "select * from SmallClass_New order by SmallClassID asc"
rs.open sql,conn,1,1
%>
<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>


<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top">
<table width="95%" border="0" cellpadding="2" cellspacing="1" class="table_southidc">
<form method="POST" name="myform" onSubmit="return CheckForm();" action="News_save.asp?action=Add" target="_self">

<tr bgcolor="#ECF5FF">
<td width="119" height="25"><font color="#FF0000">*</font>新闻类别:</td>
<td width="476"> <%
sql = "select * from BigClass_New"
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_New 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
%>
<%
ranNum=int(9*rnd)+10
iddata=month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
%>
</select></td>
</tr>


<tr>
<td height="30" colspan="2" align="center" bgcolor="#ECF5FF"> <input type="submit" name="Submit" value="提交" class="input">
 
<input type="reset" name="Submit" value="重置" class="input"> </td>
</tr>
</form>
</table></td>
</tr>
</table>
...全文
218 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
aerobic 2011-09-02
  • 打赏
  • 举报
回复
看来是个超难的问题,真的无解了。。。
aerobic 2011-09-01
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 liuchaolin 的回复:]
subcat[<%=count%>] = new Array("<%= trim(rs("SmallClassName"))%>","<%= trim(rs("BigClassID"))%>","<%= trim(rs("SmallClassID"))%>");


function changelocation(locationid)
{
document.myform.hfb……
[/Quote]

您说的没看明白。。。能贴个实例吗,谢谢~
aerobic 2011-08-31
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xiaoye_loison 的回复:]
<option value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>

把你value=value="<%=trim(rs("BigClassName")&"|"&rs("SmallClassName"))%>"
用|分割开来,可以传N个参数 接受页面用“|”分割下就可以了
[/Quote]

按照您的提示修改了:

<option selected value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassID")&"|"&rs("BigClassName"))%></option>

接收如下:
BigClassName=trim(request.form("BigClassID"|"BigClassName"))

测试了几遍,数据库没有写入数据~
aerobic 2011-08-30
  • 打赏
  • 举报
回复
看来这个问题太难了。。。没有答案啊。。。
hxkuse 2011-08-30
  • 打赏
  • 举报
回复
最不爱看这么多代码的了,,
用AJAX来做吧,,方便!
md5e 2011-08-30
  • 打赏
  • 举报
回复
subcat[<%=count%>] = new Array("<%= trim(rs("SmallClassName"))%>","<%= trim(rs("BigClassID"))%>","<%= trim(rs("SmallClassID"))%>");


function changelocation(locationid)
{
document.myform.hfbigclassname=document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].innerText;//hfbigclassname为隐含域,二级栏目也是类似这样取值
document.myform.SmallClassName.length = 1;
后浪 2011-08-30
  • 打赏
  • 举报
回复
<option value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>

把你value=value="<%=trim(rs("BigClassName")&"|"&rs("SmallClassName"))%>"
用|分割开来,可以传N个参数 接受页面用“|”分割下就可以了
aerobic 2011-08-30
  • 打赏
  • 举报
回复
另外,查看数据库BigClassName字段,写入的不是大类名(中文名),而是大类的ID(数字),不知何故?
aerobic 2011-08-30
  • 打赏
  • 举报
回复
谢谢楼上,程序提示缺少end,

.
.
.
.

loop
end if
end if
%></select>


我在这里加上end if测试,只显示大类名BigClassName,没有BigClassID和SmallClassName及SmallClassID。如何调试修改呢?谢谢~
gzwuyh 2011-08-30
  • 打赏
  • 举报
回复
设计有问题:既然级联就不需要一开始就把所有的值放到JS,一种是把大类的值传进去,另外可通过AJAX传大类,然后返回所有与大类有关的值再动态改变SmallClass
<%
dim rs
dim sql
dim BigClassID
dim SmallClassID
dim count
BigClassID=Request.QueryString("BigClassID")
SmallClassID=Request.QueryString("SmallClassID")
%>
<script language = "JavaScript">

function changelocation(bigClassID)
{
window.location='URL.asp?BidClassID='+bigClassID; //传大类ID
}

</script>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top"><table width="95%" border="0" cellpadding="2" cellspacing="1" class="table_southidc">
<form method="POST" name="myform" onSubmit="return CheckForm();" action="News_save.asp?action=Add" target="_self">
<tr bgcolor="#ECF5FF">
<td width="119" height="25"><font color="#FF0000">*</font>新闻类别:</td>
<td width="476">
<select name="BigClassName" onChange="this.value" size="1">
<%
sql = "select * from BigClass_New"
set rs=conn.execute(sql)
if rs.eof then
%>
<option value="">请添加栏目</option>
<%else
do while not rs.eof
%>
<option value="<%=trim(rs("BigClassID"))%>"
<%if trim(rs("BigClassID"))=BigClassID then '判断是否被选中%>
selected
<%end if%>
>
<%=trim(rs("BigClassName"))%></option>
<%
rs.movenext
loop
%>
</select>
<select name="SmallClassName">
<option value="" selected>不指定小类</option>
<%
if BigClassID<>"" then '如果没传入大类的ID,则有没小类选择。
sql="select * from SmallClass_New where BigClassID=" & BigClassID
do while not rs.eof
%>
<option value="<%=rs("SmallClassID")%>"
<%if trim(rs("BigClassID"))=BigClassID then '判断是否被选中%>
selected
<%end if%>
><%=rs("SmallClassName")%></option>
<% rs.movenext

loop
end if

%></select>
</td>
</tr>
<tr>
<td height="30" colspan="2" align="center" bgcolor="#ECF5FF"><input type="submit" name="Submit" value="提交" class="input">
<input type="reset" name="Submit" value="重置" class="input"></td>
</tr>
</form>
</table></td>
</tr>
</table>

28,404

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧