利用ASP嵌套JS+SQL Server打造两级连动下拉框(2)
TwoLevel.asp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>下拉列表示例</title>
</head>
<%
dim conn
dim connstr
on error resume next
set conn=server.CreateObject("ADODB.connection")
connstr="driver={SQL Server};server=wen;uid=sa;pwd=;database=DB_ProvinceCat"
conn.Open connstr
set Rs=server.createobject("ADODB.recordset")
Rs.CursorLocation = adUseClient
SQL="Select * from Tb_Province"
Rs.open SQL,conn,1,1
if Not Rs.Eof then
Dim strJScript
strJScript=""
Response.Write("<SCRIPT language=JavaScript>")&chr(13)
Response.Write("function setcategory(S){")&chr(13)
Response.Write("S.category.length="+Cstr(Rs.Recordcount+1)+";")&chr(13)
dim i
i=0
While Not Rs.Eof
strJScript=strJScript+"S.category.options["+CStr(i)+"].value="+chr(34)+Trim(Rs("ProvinceCode"))+chr(34)+";"+chr(13)
strJScript=strJScript+"S.category.options["+CStr(i)+"].text="+chr(34)+Trim(Rs("ProvinceName"))+chr(34)+";"+chr(13)
i=i+1
Rs.MoveNext
Wend
Response.write(strJScript)
Response.Write("S.category.options["+CStr(i)+"].value="+chr(34)+"无"+chr(34)+";"+chr(13))
Response.Write("S.category.options["+CStr(i)+"].text="+chr(34)+"**请选择省份**"+chr(34)+";"+chr(13))
|