從數(shù)據(jù)庫(kù)中動(dòng)態(tài)選取下拉下文的方法
發(fā)表時(shí)間:2024-06-09 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]有一頁(yè)填表的頁(yè)面,其中有幾個(gè)下拉表單是通過(guò)一個(gè)表的某個(gè)字段動(dòng)態(tài) 生成,比如省下面的城市名,希望選擇某一個(gè)省即可自動(dòng)在另一下拉表 單內(nèi)生成城市名,.....然后提交給asp處理加入到另外一個(gè)表內(nèi)。 <form name=f1 METHOD="POST"> &l...
有一頁(yè)填表的頁(yè)面,其中有幾個(gè)下拉表單是通過(guò)一個(gè)表的某個(gè)字段動(dòng)態(tài)
生成,比如省下面的城市名,希望選擇某一個(gè)省即可自動(dòng)在另一下拉表
單內(nèi)生成城市名,.....然后提交給asp處理加入到另外一個(gè)表內(nèi)。
<form name=f1 METHOD="POST">
<%
OpenDB objConn, "xxxx"
Set RSClass = objConn.Execute("SELECT * FROM class Order by fldClass")
If RSClass.EOF Then
Response.Write "沒有記錄。<BR>"
Else
Response.Write "<SELECT NAME=""class"" style=""FONT-SIZE: 9pt"" SIZE=10" & _
" ONCHANGE=""classselected(this);"" >"
sJavaScript = "function classselected(elem){" &_
vbCrlf & _
"for (var i = document.f1.sort.options.length; i >= 0; i--){" & vbCrlf & _
"document.f1.sort.options[i] = null;" & _
vbCrlf
Do Until RSClass.EOF
If sLastClass <> RSClass("fldClass") Then
sLastClass = RSClass("fldClass")
Response.Write "<OPTION VALUE=" & RSClass("fldID") & ">" & sLastClass & "</OPTION>"
sJavaScript = sJavaScript & "}" & vbCrlf & _
"if (elem.options[elem.selectedIndex].value==" & _
RSClass("fldID") & "){" & vbCrlf
End If
sJavaScript = sJavaScript & _
"document.f1.sort.options[document." & _
"f1.sort.options.length] = new Option(’" & _
RSClass("fldSort") & "’,’" & RSClass("fldID") & "’);" & _
vbCrlf
RSClass.MoveNext
Loop
Response.Write "</SELECT>"
Response.Write "<SELECT NAME=""sort"" style=""FONT-SIZE: 9pt"" SIZE=10>"
Response.Write "<OPTION>[請(qǐng)選擇]</OPTION>"
Response.Write "</SELECT>"
sJavaScript = sJavaScript & vbCrlf & "}" & vbCrlf & "}" & vbCrlf
Response.Write "<SCR" & "IPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write sJavaScript & vbCrlf & "</SCR" & "IPT>" & vbCrlf
End If
RSClass.Close
Set RSClass = Nothing%>
</form>