有一頁填表的頁面,其中有幾個下拉表單是通過一個表的某個字段動態生成,比如省下面的城市名,希望選擇某一個
省即可自動在另一下拉表單內生成城市名,.....然後提交給ASP處理加入到另外一個表內。
終於完成了,代碼如下,可能比較亂,不過還是很有效的,不用刷新頁面。
大家不妨一試~~~~~~~~
<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"" 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"" FONT-SIZE: 9pt"" SIZE=10>"
Response.Write "<OPTION>[請選擇]</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>