2016文科学霸各科笔记:关于asp三级联动菜单的问题

来源:百度文库 编辑:神马品牌网 时间:2024/04/27 23:58:24
我正在做一个三级联动菜单,但在选择第二个菜单后没能把第一个菜单的sort_id提交过去,程序如下:

<%
dim sortid,gameid
sortid=request("sort_id")
gameid=request("gameid")
set rs=server.CreateObject("adodb.recordset")
sql="select * from sort"
rs.open sql,conn,1,1
strOption1 = "<option value=''>商品类别</option>"
do while not rs.eof
if cstr(rs("sort_id")) = cstr(sortid) then
strOption1 = strOption1 & "<option value='" & rs("sort_id") & "' selected>" & rs("sort_name") & "</option>"
else

strOption1 = strOption1 & "<option value='" & rs("sort_id") & "'>" & rs("sort_name") & "</option>"

end if
rs.movenext
loop

rs.close
strOption2 = "<option value=''>游戏名称</option>"
if sortid <> "" then
sql = "select * from gametypes where class=" & sortid

rs.open sql,conn,1,1

do while not rs.eof
if cstr(rs("id")) = cstr(gameid) then
strOption2 = strOption2 & "<option value='" & rs("id") & "' selected>" & rs("gamename") & "</option>"
else
strOption2 = strOption2 & "<option value='" & rs("id") & "'>" & rs("gamename") & "</option>"
end if
rs.movenext
loop
rs.close
end if
strOption3 = "<option value=''>游戏卡</option>"
if gameid <> "" then

sql = "select * from cardstype where gametypeid="&gameid
rs.open sql,conn,1,1

while not rs.eof
if cstr(rs("id")) = cstr(cardstypeid) then
strOption3 = strOption3 & "<option value='" & rs("id") & "' selected>" & rs("cardtypename") & "</option>"
else
strOption3 = strOption3 & "<option value='" & rs("id") & "'>" & rs("cardtypename") & "</option>"
end if

rs.movenext
wend
rs.close
end if
%>

望大家多多指教

在二级option里面添加一个自定义值如 sort_id=<%=rs("class")%>
form里面添加一个<input name="sort_id" id="sort_id">
提交时通过脚本读取select.options[select.selectedIndex].sort_id赋值给input
只是给你提供一个思路,希望可以帮到你

呵呵 这个用ajax技术做比较好啊 不用刷新 的 效果最好 可以不提交页面