ASP實現省,大學二級聯動(轉,改)

來源:互聯網
上載者:User
今天在公司裡項目裡要用到二級聯動,還是ASP的,ASP.NET的話就好搞定。好長時間沒有動過ASP了。

在網上找了些資料改了改。實現了這個功能,代碼如下:

ASP二級聯動
省表:sheng:sid,stitle.學校表:cid,ctitle,sid

<!--#include file="../sub/conn.asp"-->
<html><head><title></title>
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
   if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>

<body>
<form method="post" name="myform" id="myform" >
<select name="first" onChange="MM_jumpMenu('parent',this,0)">
<%
sqlt2 = "select * from sheng"
set rst2=server.createobject("adodb.recordset")
rst2.open sqlt2,conn,0,1
if rst2.eof or rst2.bof then
response.write "<option>-請選擇-</option>" '如果沒有記錄,就顯示-----
else
while not(rst2.eof or rst2.bof) '有記錄,就將父名稱列出來,形成下拉。
   %>
   <option value="?sec=<%=rst2("sid")%>&class_1=<%=rst2("stitle")%>" <%if cstr(rst2("sid")) = request.querystring("sec") then %>selected<%end if%>><%=rst2("stitle")%></option>
   <%rst2.movenext
wend
rst2.movefirst '將遊標移到第一條,以備下面之用。
end if
%>
</select>
<input name="class_1" type="hidden" id="class_1" value="<%=request("class_1")%>">
<select name="second">
<%
if rst2.eof or rst2.bof then
response.write ("<option>-請選擇-</option>")
else
if request.querystring("sec") = "" then '擷取跳轉之後的sec值
   temp=rst2("sid")' 如果為空白,就把temp的值設為第一條記錄的值
else
   temp = request.querystring("sec") '否則就為收到的值
end if
   subsql = "select * from school where sid="&temp&""
   set subrs=server.createobject("adodb.recordset")
   subrs.open subsql,conn,0,1
   if subrs.eof or subrs.bof then
   response.write ("<option>-請選擇-</option>")
   '如果沒有記錄,則在這個列表中顯示"-----"
   else
   while not(subrs.eof or subrs.bof)'否則就用迴圈列出一切合格記錄。
   response.write ("<option value=" & subrs("ctitle") & ">" & subrs("ctitle") & "</option>")
   subrs.movenext
   wend
   end if
end if

'關閉所有的記錄集
subrs.close
set subrs = nothing
rst2.close
set rst2 = nothing
%>
</select>
</form>


</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.