从数据库中动态选取下拉列表的方法

有一页填表的页面,其中有几个下拉表单是通过一个表的某个字段动态
生成,比如省下面的城市名,希望选择某一个省即可自动在另一下拉表
单内生成城市名,.....然后提交给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"" 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>[请选择]</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>

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

打赏
文章很值,打赏犒劳作者一下
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页

打赏

fbj007

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者