我很早以前写的二级联动源代码,里面用的是省市联动
选择省份第二个列表框显示相应的城市
[CODE]<!--#include file="UserControl.asp"-->
<!--#include file="Cls\WebSiteSetInf.asp"-->
<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<%
'网页样式初始化代码
Dim PageStyleT
Dim oWebI
Set oWebI=New WebSetInf
Set PageStyleT=New PageStyle
Call QueryStyle("真实资料修改",PageStyleT)
%>
<TITLE><%=oWebI.WebName%>-真实资料修改</TITLE>
<style type="text/css">
<!--
<%=PageStyleT.StyleString%>
-->
</style>
<STYLE type=text/css>
<!--
body {
background-color: <%=PageStyleT.BackGround%>;
}
.style4 {font-size: 14px}
.style5 {font-size: 12px}
-->
</STYLE>
<%
'网页初始化区域
Dim UsR
Dim ControlR
Dim UsName
Dim rsRe
Set UsR=New User
Set ControlR=New UserControl
IF Session("UserName")<>"" Then
UsName=Session("UserName")
Else
Response.Redirect "ErrPage.asp?ErrorMessage=您还没有登录请先登陆"
End IF
ControlR.Initialize
ControlR.ReturnReaInformation UsName,UsR
ControlR.ReturnWebSiteInformation UsName,UsR
ControlR.ReturnBasicInformation UsName,UsR
UsR.UserBirthday=ControlR.RuturnBirthday(UsName)
UsR.UserSex=ControlR.RuturnSex(UsName)
%>
<script language="javascript">
//声明信息储存变量
var UserRealName;
var UserNation;
var UserProvince;
var UserCity;
var UserJob;
var UserEdu;
var UserBlood;
var UserZodiac;
var UserBelieve;
var UserPhone;
var UserMailAddress;
var UserBiref;
//网页初始化函数
function PageInit()
{
document.fUserBiref.UserBiref.value=document.fUserBiref.bValue.value;
<%
'服务器端输入有效性验证代码'
Dim ReFalse
ReFalse="T"
IF Request.Form("IsSubmit")="T" Then
'//TODO:服务器端有效性验证代码'
IF Request.Form("UserRealName")="" Then
Response.Write("alert("&"""真实姓名为空"""&");")
ReFalse="F"
End IF
IF ReFalse<>"F" Then
IF Len(Request.Form("UserRealName"))>10 Then
Response.Write("alert("&"""真实姓名长度过大,注:最大10个字符"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Request.Form("UserNation")="" Then
Response.Write("alert("&"""国家为空"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Len(Request.Form("UserNation"))>10 Then
Response.Write("alert("&"""国家长度过大,注:最大10个字符"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Request.Form("UserProvince")="" Then
Response.Write("alert("&"""省份为空"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Len(Request.Form("UserProvince"))>10 Then
Response.Write("alert("&"""省份长度过大,注:最大10个字符"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Request.Form("UserCity")="" Then
Response.Write("alert("&"""城市为空"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Len(Request.Form("UserCity"))>10 Then
Response.Write("alert("&"""城市长度过大,注:最大10个字符"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Request.Form("UserJob")="" Then
Response.Write("alert("&"""职业为空"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Len(Request.Form("UserJob"))>50 Then
Response.Write("alert("&"""职业长度过大,注:最大50个字符"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Request.Form("UserEdu")="" Then
Response.Write("alert("&"""学历为空"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Len(Request.Form("UserEdu"))>50 Then
Response.Write("alert("&"""学历长度过大,注:最大50个字符"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Request.Form("UserBlood")="" Then
Response.Write("alert("&"""血型为空"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Len(Request.Form("UserBlood"))>7 Then
Response.Write("alert("&"""血型长度过大,注:最大7个字符"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Request.Form("UserBelieve")="" Then
Response.Write("alert("&"""信仰为空"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Len(Request.Form("UserJob"))>50 Then
Response.Write("alert("&"""信仰长度过大,注:最大50个字符"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Request.Form("UserPhone")="" Then
Response.Write("alert("&"""电话为空"""&");")
ReFalse="F"
Else
IF ReFalse<>"F" Then
On Error Resume Next
IF VarType(CDbl(Request.Form("UserPhone")))<>5 Then
Response.Write("alert("&"""电话非数字"""&");")
ReFalse="F"
End IF
End IF
End IF
End IF
IF ReFalse<>"F" Then
IF Request.Form("UserMailAddress")="" Then
Response.Write("alert("&"""通讯地址为空"""&");")
ReFalse="F"
End IF
End IF
IF ReFalse<>"F" Then
IF Request.Form("UserBiref")<>"" Then
IF Len(Request.Form("UserBiref"))>300 Then
Response.Write("alert("&"""签名长度大于300个字"""&");")
ReFalse="F"
End IF
End IF
End IF
IF ReFalse<>"F" Then
UsR.UserRealName=Request.Form("UserRealName")
UsR.UserNation=Request.Form("UserNation")
UsR.UserProvince=Request.Form("UserProvince")
UsR.UserCity=Request.Form("UserCity")
UsR.UserJob=Request.Form("UserJob")
UsR.UserEdu=Request.Form("UserEdu")
UsR.UserZodiac=Request.Form("UserZodiac")
UsR.UserBlood=Request.Form("UserBlood")
UsR.UserBelieve=Request.Form("UserBelieve")
UsR.UserPhone=Request.Form("UserPhone")
UsR.UserMailAdderss=Request.Form("UserMailAddress")
UsR.UserBiref=Request.Form("UserBiref")
Set rsRe=Server.CreateObject("ADODB.RecordSet")
rsRe.Open "UserReal",con,1,3
Do Until rsRe.EOF
IF rsRe.Fields(1).value=UsR.UserName Then
Exit Do
End IF
rsRe.MoveNext
Loop
IF rsRe.EOF=True Then
Dim SQLInst
SQLInst="INSERT INTO UserReal VALUES("
SQLInst=SQLInst&UsR.UserID&","
SQLInst=SQLInst&"'"&UsR.UserName&"',"
SQLInst=SQLInst&"'"&UsR.UserRealName&"',"
SQLInst=SQLInst&"'"&UsR.UserNation&"',"
SQLInst=SQLInst&"'"&UsR.UserProvince&"',"
SQLInst=SQLInst&"'"&UsR.UserCity&"',"
SQLInst=SQLInst&"'"&UsR.UserJob&"',"
SQLInst=SQLInst&"'"&UsR.UserEdu&"',"
SQLInst=SQLInst&"'"&UsR.UserZodiac&"',"
SQLInst=SQLInst&"'"&UsR.UserBlood&"',"
SQLInst=SQLInst&"'"&UsR.UserBelieve&"',"
SQLInst=SQLInst&UsR.UserPhone&","
SQLInst=SQLInst&"'"&UsR.UserMailAdderss&"',"
SQLInst=SQLInst&"'"&UsR.UserBiref&"'"
SQLInst=SQLInst&")"
Response.Write "//"&SQLInst&Chr(13)
con.Execute SQLInst
Else
Dim SQLUpdate
SQLUpdate="UPDATE UserReal SET "
SQLUpdate=SQLUpdate&"UserRealityName='"&UsR.UserRealName&"',"
SQLUpdate=SQLUpdate&"UserNation='"&UsR.UserNation&"',"
SQLUpdate=SQLUpdate&"UserPro='"&UsR.UserProvince&"',"
SQLUpdate=SQLUpdate&"UserCity='"&UsR.UserCity&"',"
SQLUpdate=SQLUpdate&"UserJob='"&UsR.UserJob&"',"
SQLUpdate=SQLUpdate&"UserEdu='"&UsR.UserEdu&"',"
SQLUpdate=SQLUpdate&"UserZodiac='"&UsR.UserZodiac&"',"
SQLUpdate=SQLUpdate&"UserBlood='"&UsR.UserBlood&"',"
SQLUpdate=SQLUpdate&"UserBelieve='"&UsR.UserBelieve&"',"
SQLUpdate=SQLUpdate&"UserPhone="&UsR.UserPhone&","
SQLUpdate=SQLUpdate&"UserMailAdderss='"&UsR.UserMailAdderss&"',"
SQLUpdate=SQLUpdate&"UserBiref='"&UsR.UserBiref&"'"
SQLUpdate=SQLUpdate&" WHERE UserName='"&UsR.UserName&"'"
con.Execute SQLUpdate
End IF
Response.Write("alert("&"""信息修改成功"""&");")
End IF
End IF
%>
}
//两级联动下拉列表函数
function SelCityChange(txt)
{
var tAry;
var tAryNum;
var tNum;
document.City.textCity.value=txt;
tAryNum=0;
tNum=0;
for(var i=0;i<document.townAry.town.length;i++)
{
if(document.townAry.town[i].id==txt)
{
tAryNum=tAryNum+1
}
}
tAry=new Array(tAryNum);
for(var j=0;j<document.townAry.town.length;j++)
{
if(document.townAry.town[j].id==txt)
{
tAry[tNum]=document.townAry.town[j].value;
tNum=tNum+1
}
}
document.Town.selTown.options.length=tAryNum;
for(var k=0;k<tAryNum;k++)
{
document.Town.selTown.options[k].value=tAry[k];
document.Town.selTown.options[k].text=tAry[k];
}
}
//生肖选择函数
function SelZobidac(txt)
{
UserZodiac=txt;
}
//重填按钮函数
function ResetForm()
{
document.fUserRealName.UserRealName.value="";
document.fUserNation.UserNation.value="";
document.City.textCity.value="";
document.Town.textTown.value="";
document.fUserJob.UserJob.value="";
document.fUserEdu.UserEdu.value="";
document.fUserBlood.UserBlood.value="";
document.fUserBelieve.UserBelieve.value="";
document.fUserPhone.UserPhone.value="";
document.fUserMailAddress.UserMailAddress.value="";
document.fUserBiref.UserBiref.value="";
}
//客户端验证提交函数
function VerifyCilck()
{
//得到提交信息
UserRealName=document.fUserRealName.UserRealName.value;
UserNation=document.fUserNation.UserNation.value;
UserProvince=document.City.textCity.value;
UserCity=document.Town.textTown.value;
UserJob=document.fUserJob.UserJob.value;
UserEdu=document.fUserEdu.UserEdu.value;
UserBlood=document.fUserBlood.UserBlood.value;
UserBelieve=document.fUserBelieve.UserBelieve.value;
UserPhone=document.fUserPhone.UserPhone.value;
UserMailAddress=document.fUserMailAddress.UserMailAddress.value;
UserBiref=document.fUserBiref.UserBiref.value;
//有效性验证
if(confirm("确认所有信息以填写正确?"))
{
if(UserRealName=="")
{
alert("真实姓名为空");
return false;
}
if(UserNation=="")
{
alert("国家为空");
return false;
}
if(UserProvince=="")
{
alert("省份为空");
return false;
}
if(UserCity=="")
{
alert("城市为空");
return false;
}
if(UserJob=="")
{
alert("职业为空");
return false;
}
if(UserEdu=="")
{
alert("学历为空");
return false;
}
if(UserBlood=="")
{
alert("血型为空");
return false;
}
if(UserBelieve=="")
{
alert("信仰为空");
return false;
}
if(UserPhone=="")
{
alert("电话为空");
return false;
}
if(UserMailAddress=="")
{
alert("通讯地址为空");
return false;
}
if(UserZodiac=="")
{
alert("请选择属性");
return false;
}
//将信填写息赋给表单并提交到服务器
document.SubFrom.UserRealName.value=UserRealName;
document.SubFrom.UserNation.value=UserNation;
document.SubFrom.UserProvince.value=UserProvince;
document.SubFrom.UserCity.value=UserCity;
document.SubFrom.UserJob.value=UserJob;
document.SubFrom.UserEdu.value=UserEdu;
document.SubFrom.UserZodiac.value=UserZodiac;
document.SubFrom.UserBlood.value=UserBlood;
document.SubFrom.UserBelieve.value=UserBelieve;
document.SubFrom.UserPhone.value=UserPhone;
document.SubFrom.UserMailAddress.value=UserMailAddress;
document.SubFrom.UserBiref.value=UserBiref;
document.SubFrom.IsSubmit.value="T";
document.SubFrom.submit();
}
}
</script>
<META content="MSHTML 6.00.2800.1491" name=GENERATOR></HEAD>
<BODY onLoad="PageInit();">
<TABLE cellSpacing=0 cellPadding=0 width=387 height="377" border=0><!--DWLayoutTable-->
<TBODY>
<TR>
<TD height=20 colspan="2" vAlign=top>
<DIV align=center class=style4>
<div align="left">真实姓名</div>
</DIV></TD>
<TD colspan="5" vAlign=top><form name="fUserRealName" method="post" style="height:20px ">
<input type="text" style="width:120px; height:20px " name="UserRealName" value=<%=UsR.UserRealName%>>
</form></TD>
<TD colspan="3" vAlign=top>
<DIV class=style4
align=center>国家</DIV></TD>
<TD colspan="4" vAlign=top><form name="fUserNation" style="height:20px" method="post">
<input type="text" style="width:155px; height:20px" name="UserNation" value=<%=UsR.UserNation%>>
</form></TD>
</TR>
<TR>
<TD width="33" height=20 vAlign=top>
<DIV align=center><SPAN
class=style4>省份</SPAN></DIV></TD>
<TD colspan="5" vAlign=top>
<form name="City" method="post" style="height:20px ">
<input type="text" style="width:63px; height:20px"name="textCity" value=<%=UsR.UserProvince%>>
<select style="width:65px;height:15px" name="selCity" onChange="SelCityChange(City.selCity.options[selectedIndex].value)">
<option selected>请选择省份</option>
<%
Dim rsProvince
Set rsProvince=Server.CreateObject("ADODB.RecordSet")
rsProvince.Open "Province",con,1,3
Do Until rsProvince.EOF
Response.Write("<option value="&rsProvince.Fields(0).value&">"&rsProvince.Fields(0).value&"</option>"&Chr(13))
rsProvince.MoveNext
Loop
rsProvince.Close
Set rsProvince=Nothing
%>
</select>
</form></TD>
<TD colspan="3" vAlign=top>
<DIV align=center><SPAN
class=style4>城市</SPAN></DIV></TD>
<TD colSpan=5 vAlign=top><form name="Town" method="post" style="height:20px ">
<input type="text" style="width:63px; height:20px"name="textTown" value=<%=UsR.UserCity%>>
<select style="width:77px;height:15px" name="selTown" onChange="Town.textTown.value=Town.selTown.options[selectedIndex].value;">
<option selected>请选择城市</option>
</select>
</form></TD>
</TR>
<TR>
<TD height=20 vAlign=top>
<DIV align=center><SPAN
class=style4>职业</SPAN></DIV></TD>
<TD colspan="2" vAlign=top><form name="fUserJob" method="post" style="height:20px ">
<input style="width:87px; height:20px "type="text" name="UserJob" value="<%=UsR.UserJob%>">
</form></TD>
<TD width="30" vAlign=top>
<DIV align=center><SPAN
class=style4>学历</SPAN></DIV></TD>
<TD colspan="6" vAlign=top><form name="fUserEdu" method="post" style="height:20px ">
<input style="width:75px; height:20px "type="text" name="UserEdu" value=<%=UsR.UserEdu%>>
</form></TD>
<TD colSpan=2 vAlign=top>
<DIV align=center><SPAN
class=style4>血型</SPAN></DIV></TD>
<TD colspan="2" vAlign=top><form name="fUserBlood" method="post">
<input style="width:116px; height:20px; "type="text" name="UserBlood" value=<%=UsR.UserBlood%>>
</form></TD>
</TR>
<TR>
<TD height=20 vAlign=top>
<DIV align=center><SPAN
class=style4>生肖</SPAN></DIV></TD>
<TD colspan="4" vAlign=top><form name="fUserZodiac" method="post">
<select name="UserZodiac" style="width:120px; height:13px" onChange="SelZobidac(fUserZodiac.UserZodiac.options[selectedIndex].value);">
<%
IF UsR.UserZodiac="" Then
Response.Write("<option selected>请 选 择 生 肖</option>"&Chr(13))
Else
Response.Write("<option value="&UsR.UserZodiac&"selected>"&UsR.UserZodiac&"</option>"&Chr(13))
End IF
%>
<option value="鼠">子 鼠</option>
<option value="牛">丑 牛</option>
<option value="虎">寅 虎</option>
<option value="兔">牟 兔</option>
<option value="龙">晨 龙</option>
<option value="蛇">巳 蛇</option>
<option value="马">午 马</option>
<option value="羊">未 羊</option>
<option value="猴">申 猴</option>
<option value="鸡">酉 鸡</option>
<option value="狗">戌 狗</option>
<option value="猪">亥 猪</option>
</select>
</form></TD>
<TD colspan="3" vAlign=top>
<DIV align=center><SPAN
class=style4>信仰</SPAN></DIV></TD>
<TD colSpan=6 vAlign=top><form name="fUserBelieve" method="post">
<input style="width:180px; height:20px "type="text" name="UserBelieve" value=<%=UsR.UserBelieve%>>
</form></TD>
</TR>
<TR>
<TD height=20 colspan="2" vAlign=top>
<div align="left"><SPAN
class=style4>联系电话</SPAN></div></TD>
<TD colspan="4" vAlign=top><form name="fUserPhone" method="post">
<input style="width:110px; height:20px "type="text" name="UserPhone" value=<%=UsR.UserPhone%>>
</form></TD>
<TD colspan="5" vAlign=top>
<DIV align=center><SPAN
class=style4>通讯地址</SPAN></DIV></TD>
<TD colSpan=3 vAlign=top><form name="fUserMailAddress" method="post">
<input style="width:142px; height:20px "type="text" name="UserMailAddress" value=<%=UsR.UserMailAdderss%>>
</form></TD>
</TR>
<TR>
<TD height=12 colSpan=14 vAlign=top>
<DIV
align=center class=style5>个 人 简 介</DIV></TD>
</TR>
<TR>
<TD height=87 colSpan=14 vAlign=top><form name="fUserBiref" method="post">
<div align="center">
<TEXTAREA style="WIDTH: 387px; HEIGHT: 70px" name="UserBiref" rows=3 cols=42 ALIGN="BOTTOM"></TEXTAREA>
<input name="bValue" type="hidden" value="<%=Server.HTMLEncode(UsR.UserBiref)%>">
</div>
</form></TD>
</TR>
<TR>
<TD height=21 colSpan=14 vAlign=top>
<DIV align=center><INPUT type="button" value=确定 name=Submit onClick="VerifyCilck();">
<INPUT type=Button value=重填 name=Submit2 onClick="ResetForm();">
</DIV></TD>
</TR>
<TR>
<TD height="20" colspan="13" vAlign=top>
<form name="SubFrom" method="post" action="UserRealityEdit.asp">
<input type="hidden" name="UserRealName">
<input type="hidden" name="UserNation">
<input type="hidden" name="UserProvince">
<input type="hidden" name="UserCity">
<input type="hidden" name="UserJob">
<input type="hidden" name="UserEdu">
<input type="hidden" name="UserZodiac">
<input type="hidden" name="UserBlood">
<input type="hidden" name="UserBelieve">
<input type="hidden" name="UserPhone">
<input type="hidden" name="UserMailAddress">
<input type="hidden" name="UserBiref">
<input type="hidden" name="IsSubmit">
</form></TD>
<td width="11"></td>
</TR>
<TR>
<TD height="43" colspan="13" vAlign=top>
<form name="townAry" method="post">
<%
Dim rsTown
Set rsTown=Server.CreateObject("ADODB.RecordSet")
rsTown.Open "City",con,1,3
Do Until rsTown.EOF
Response.Write("<input type=hidden name=town id="""&rsTown.Fields(0).value&""" value="&rsTown.Fields(1).Value&">"&Chr(13))
rsTown.MoveNext
Loop
%>
</form></TD>
<td></td>
</TR>
<TR>
<TD height="173"> </TD>
<TD width="38"> </TD>
<TD width="52"> </TD>
<TD> </TD>
<TD width="19"> </TD>
<TD width="9"> </TD>
<TD width="11"> </TD>
<TD width="15"> </TD>
<TD width="14"> </TD>
<TD width="11"> </TD>
<TD width="13"> </TD>
<TD width="25"> </TD>
<TD width="106"> </TD>
<td></td>
</TR>
</TBODY></TABLE>
</BODY>
<%
'网页对象析构区域
rsRe.Close()
Set rsRe=Nothing
Set PageStyleT=Nothing
Set UsR=Nothing
Set oWebI=Nothing
Set ControlR=Nothing
%>
</HTML>[/CODE]