<!--#include file="link/sqlcn.asp"-->
<HTML>
<HEAD>
<%
function d(id)
dim f
set ca=server.CreateObject("adodb.recordset")
ca.open"select * from city where provinceid='"&
id &"'",sqlce,1,1
do
while not ca.eof
if f="" then
f=trim(ca("cityname"))
else
f=f&"','"&trim(ca("cityname"))
end if
ca.movenext
loop
d=f
end function
function u(id)
dim x
set co=server.CreateObject("adodb.recordset")
co.open"select * from city where provinceid='"&
id &"'",sqlce,1,1
do
while not co.eof
if x="" then
x=trim(co("cityid"))
else
x=x&"','"&trim(co("cityid"))
end if
co.movenext
loop
u=x
end function
function c
set ce=server.createobject("adodb.recordset")
ce.open"select provinceid from province",sqlce,1,1
dim m
do
while not ce.eof
m=m&"case '"&trim(ce("provinceid"))&"':"&vbCrlf&_
"var labels = new Array('"&
d(trim(ce("provinceid"))) &"');"&vbCrlf&_
"var values = new Array('"&
u(trim(ce("provinceid"))) &"');"&vbCrlf&_
"break;"&vbCrlf
ce.movenext
loop
c=m
end function
%>
<%response.Write("<SCRIPT LANGUAGE=JavaScript>"&vbCrlf&_
"function setcity() {"&vbCrlf&_
"switch (document.shengshi.sheng.value) {"&vbCrlf&_
c&_
"}"&vbCrlf&_
"document.shengshi.city.options.length = 0;"&vbCrlf&_
"for(var i = 0;
i < labels.length;
i++) {"&vbCrlf&_
"document.shengshi.city.add(document.createElement('OPTION'));"&vbCrlf&_
"document.shengshi.city.options.text=labels;"&vbCrlf&_
"document.shengshi.city.options.value=values;"&vbCrlf&_
"}"&vbCrlf&_
"document.shengshi.city.selectedIndex = 0;"&vbCrlf&_
"}"&vbCrlf&_
"</SCRIPT>")
%>
</HEAD>
<BODY>
<FORM NAME="shengshi" action="a.asp" method="post">
省:
<SELECT NAME="sheng" OnChange="setcity()">
<% set cdm=server.createobject("adodb.recordset")
cdm.open"select * from province",sqlce,1,1
do
while not cdm.eof %>
<OPTION value=<% =trim(cdm("provinceid")) %>><% =trim(cdm("provincename")) %></OPTION>
<% cdm.movenext
loop
%>
</SELECT>
市:
<SELECT NAME="city">
</SELECT>
<input type=submit>
</FORM>
<script language="JavaScript">
<!--
setcity()
-->
</script>
</BODY>
</HTML>
呵呵,一个同事弄出来的,你自己回去慢慢看吧,反正是可以用了