[原创]客户端表单验证 |
我在做注册表单时想用javascript在客户端验证是否为空后在去进一步让服务器验证,我写的部分代码如下,可是老是只能验证用户名这一项,也
就是说我填了用户名后如果其他项不填的话,就不回在弹出对话框警告你了.
就是下面这段代码如果去掉第3个if前面的注释符后就可以得到验证,但只能验证用户名这一项.
我现在想让javascript在客户端依次将这些项都验证后再去服务器验证,请问斑竹这应该怎么该呀??
如果我没说清楚的话,还麻烦斑竹亲自运行以下这段代码看看问题究竟出在哪了,好吗?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>zhucebiaodan</title>
<script language=JavaScript>
function checkSubmit()
{ if((document.form1.username.value) =="")
{ window.alert("请输入用户名");
documet.form1.username.focus();
return false;
}
else
{return true;
}
if((documet.form1.password.value) =="")
{ window.alert("请输入正确密码");
document.form1.password.focus();
return false;
}
else
{return true;
}
/* if((document.form1.password.length)<4"")
{ window.alert("请输入正确密码");
document.form1.password.focus();
return false;
}
else
{return true;
}
if((document.form1.password.value)!=(document.form1.repassword.value) )
{ window.alert("您两次输入的密码不同,请重输");
document.form1.repassword.focus();
return false;
}
else
{return true;
}
if((document.form1.nick.value)=="")
{ window.alert("请输入昵称");
document.form1.nick.focus();
return false;
}
else
{return true;
} */
return true;
}
</script>
</head>
<body>
<form name="form1" action="register.php" method="post" onsubmit="javascript:return checkSubmit()">
<table width="789" height="442" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#66CC66">
<tr>
<td width="83"> 用户ID:</td>
<td width="694"> <input type="text" name="textfield"> </td>
</tr>
<tr>
<td>用户名:</td>
<td> <input type="text" name="username"> </td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password">
<?php if($erro=="1") echo "用户名已存在" ?></td>
</tr>
<tr>
<td height="31"> </td>
<td><p><font face="隶书"><strong>合法密码必须由4到20各字符组成,</strong></font><font face="隶书"><strong>可由英文字母
(大小写不限)和阿拉伯数字组成;</strong></font></p>
</td>
</tr>
<tr>
<td>重复密码:</td>
<td><input type="password" name="repassword"></td>
</tr>
<tr>
<td>昵称:</td>
<td><input type="text" name="nick"></td>
</tr>
<tr>
<td>姓名:</td>
<td><input type="radio" name="xingming" value="radiobutton">
男
<input type="radio" name="" value="radiobutton">
女</td>
</tr>
<tr>
<td>性别:</td>
<td><input type="text" name="textfield6"></td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="text" name="textfield7"></td>
</tr>
<tr>
<td>地区:</td>
<td><select name="select">
<option selected>北京</option>
<option>上海</option>
<option>西安</option>
<option>深圳</option>
<option>大连</option>
</select></td>
</tr>
<tr>
<td height="71">爱好:</td>
<td><p>
<input type="checkbox" name="checkbox" value="checkbox">
音乐
<input type="checkbox" name="checkbox2" value="checkbox">
体育
<input type="checkbox" name="checkbox3" value="checkbox">
看书
<input type="checkbox" name="checkbox4" value="checkbox">
文学</p>
<p>
<input type="checkbox" name="checkbox5" value="checkbox">
交友
<input type="checkbox" name="checkbox6" value="checkbox">
聊天
<input type="checkbox" name="checkbox7" value="checkbox">
军事 </p>
<p>
<input type="checkbox" name="checkbox8" value="checkbox">
上网
<input type="checkbox" name="checkbox9" value="checkbox">
游戏 </p></td>
</tr>
<tr>
<td>详细地址:</td>
<td><input type="text" name="textfield112"></td>
</tr>
<tr>
<td>QQ:</td>
<td><input type="text" name="textfield11"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="textfield12"></td>
</tr>
<tr>
<td>Tel:</td>
<td><input type="text" name="textfield13"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="提交"> <input type="submit" name="Submit2" value="重置
"></td>
</tr>
</table>
</form>
</body>
</html> |
|
|