其他的账号密码都可以拦住,但是地址不管有没有选,只要提交就可以跳到servlet,而且只要账号密码都填了,就算onsubmit里面check函数全部设置为return false 一样可以跳
<head>
<base href="<%=basePath%>">
<title>用户注册</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script language="javascript" src="checkForm.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>/js/My97DatePicker/WdatePicker.js"></script>
<!-- 二级联动下拉框 -->
<script language="JavaScript" type="text/javascript">
var city=[
["北京","天津","上海","重庆"],
["南京市","苏州市","南通市","常州市"],
["福州市","福安市","龙岩市","南平市"],
["广州市","潮阳市","潮州市","澄海市"],
["兰州市","白银市","定西市","敦煌市"]
];
function getCity(){
var sltProvince=document.userform.province;
var sltCity=document.userform.city;
var provinceCity=city[sltProvince.selectedIndex - 1];
sltCity.length=1;
for(var i=0;i< provinceCity.length;i++){
sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
}
}
</script>
</head>
<body>
<form name="userform" action="servlet/AddUserServlet" method="post" onsubmit="return check()">
<table align="center" border="1" width="440px">
<tr>
<td colspan="2" align="center" >用户注册表</td>
</tr>
<tr>
<td align="center">用户姓名</td>
<td>
<input type="text" name="uname" size="" onblur="checkUname(this.value)">
<span id="unameErr"></span>
</td>
</tr>
<tr>
<td align="center">用户密码</td>
<td>
<input type="password" name="upwd" onblur="checkUpwd(this.value)">
<span id="upwdErr"></span>
</td>
</tr>
<tr>
<td align="center">确认密码</td>
<td>
<input type="password" name="upwd2" onblur="checkUpwd2(this.value)">
<span id="upwd2Err"></span>
</td>
</tr>
<tr>
<td align="center">用户性别</td>
<td>
<input type="radio" name="usex" value="男" checked>男
<input type="radio" name="usex" value="女">女
</td>
</tr>
<tr>
<td align="center">出生日期</td>
<td>
<input name="strbirth" class="Wdate" type="text" id="d16" onfocus="WdatePicker({position:{right:100,top:50}})"/>
</td>
</tr>
<tr>
<td align="center">用户住址</td>
<td>
<SELECT NAME="province" onChange="getCity()" onblur="checkUaddr(this.value)">
<OPTION VALUE="">请选择所在省份</OPTION>
<OPTION VALUE="直辖市">直辖市</OPTION>
<OPTION VALUE="江苏省">江苏省</OPTION>
<OPTION VALUE="福建省">福建省</OPTION>
<OPTION VALUE="广东省">广东省</OPTION>
<OPTION VALUE="甘肃省">甘肃省</OPTION>
</SELECT>
<SELECT NAME="city" onblur="checkUaddr(this.value)">
<OPTION VALUE="">请选择所在城市</OPTION>
</SELECT>
<span id="uaddrErr"></span>
</td>
</tr>
<tr><td colspan="2" align="center">
<input type="submit" value="确定" style="width: 82px; ">
<input type="reset" value="重置" style="width: 82px; ">
</td></tr>
</table>
这是checkForm.js
function check() {
if(!checkUname(document.userform.uname.value)){
return false;
}else if(!checkUpwd(document.userform.upwd.value)){
return false;
}else if(!checkUpwd2(document.userform.upwd2.value)){
return false;
}else if(!checkUaddr(document.userform.province.value)){
return false;
}else if(!checkUaddr(document.userform.city.value)){
return false;
}else {
return true;
}
}
function checkUname(str) {
if(str == "") {
document.getElementById("unameErr").innerHTML="用户名不能为空";
userform.uname.focus();
return false;
}else {
document.getElementById("unameErr").innerHTML="验证通过";
return true;
}
}
function checkUpwd(str) {
if(str == "") {
document.getElementById("upwdErr").innerHTML="密码不能为空";
userform.upwd.focus();
return false;
}else if(strlen(str) < 6) {
document.getElementById("upwdErr").innerHTML="密码不能低于6位";
userform.upwd.focus();
return false;
}
else {
document.getElementById("upwdErr").innerHTML="验证通过";
return true;
}
}
function checkUpwd2(str) {
if(str == "") {
document.getElementById("upwd2Err").innerHTML="密码不能为空";
userform.upwd.focus();
return false;
}else if(str != document.userform.upwd.value) {
document.getElementById("upwd2Err").innerHTML="两次输入的密码不一致";
userform.upwd2.focus();
return false;
}else {
document.getElementById("upwd2Err").innerHTML="验证通过";
return true;
}
}
function checkUaddr(str) {
if(str == "") {
document.getElementById("uaddrErr").innerHTML="地址不能为空";
userform.uaddr.focus();
return false;
}else {
document.getElementById("uaddrErr").innerHTML="验证通过";
return true;
}
}
function strlen(str) {
var i;
var len=0;
for(i = 0;i < str.length;i++) {
if(str.charCodeAt(i) > 255) len += 2;
else len++;
}
return len;
}