<form action="<?php echo $editFormAction; ?>" "method="post" name="form2" id="form2" onsubmit="MM_validateForm('username','','R','upassword','','R');return document.MM_returnValue">
<table width="614" align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">用户名:</td>
<td><input name="username" type="text" id="username" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">密码:</td>
<td><input name="upassword" type="password" id="upassword" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">重复密码:</td>
<td><input name="repassword" type="password" id="repassword" value="" size="32" /></td>
var repwd = document.getElementById("repassword").value;
if (pwd == "") { 这是为空的
} else if (repwd == "") { 重复密码为空的
} else if (pwd != repwd) { 两次输入不相同
}
这里最好用正则表达式或者其他什么方法为javascript加一个trim()方法,把两边空格去掉
用jquery也可以实现
function on_submit(){
var username=document.getElementById("username");
var pwd=document.getElementById("upassword");
var repwd=document.getElementById("repassword");
if(pwd.value!=repwd.value){
alert("两次密码不一致");
pwd.value="";
repwd.value="";
pwd.focus();
return false;
}
}
</script>
</head>
<body>
<form action="" method="post" name="form2" id="form2" onsubmit="return on_submit()">
<table width="614" align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">用户名:</td>
<td><input name="username" type="text" id="username" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">密码:</td>
<td><input name="upassword" type="password" id="upassword" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">重复密码:</td>
<td><input name="repassword" type="password" id="repassword" value="" size="32" /></td>
</tr>
<tr><td></td><td><input type="submit" value="确定" /></td></tr>
</table>
</form>
</body>