为什么我用document.getElementById()没有办法验证数据?一按提交就自动转到servlet里了,求教.........
附上部分代码:
<script type="text/javascript">
function checkpw(){
var old=document.getElementById("oldpw");
var new1=document.getElementById("new1pw");
var new2=document.getElementById("new2pw");
if(new1.value!=new2.value){
alert("新密码不一致,请正确填写");
return false;
}
if(old.value==""||new1.value==""||new2.value==""){
alert("请补全资料");
return false;
}
return true;
}
</script>
........
<form action="PWServlet" method="post" onSubmit="return checkpw();'">
<table>
<tr><td> 旧密码: <input class="input" type="password" id="oldpw" name="old"></td></tr>
<tr><td> </td></tr>
<tr><td> 新密码: <input class="input" type="password" id="new1pw" name="new"></td></tr>
<tr><td> </td></tr>
<tr><td>确认密码:<input class="input" type="password" id="new2pw" name="new2"></td></tr>
<tr><td> </td></tr>
<tr><td><center><input class="button" type="submit" value="确定"></center></td></tr>
</table>
</form>
感觉连函数都没有执行,求解......
------解决方案--------------------
多了个单引号...
<form action="PWServlet" method="post" onsubmit="return checkpw();">