Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重新键入密码验证无效_Javascript - Fatal编程技术网

Javascript 重新键入密码验证无效

Javascript 重新键入密码验证无效,javascript,Javascript,我使用了以下代码: <script type="text/javascript"> function validate() { if ((document.changepass.newpassword.value != '') && (document.changepass.retypenewpassword.value == document.changepass.newpassword.value)){ document.chang

我使用了以下代码:

<script type="text/javascript">
function validate() {
    if ((document.changepass.newpassword.value != '') &&
(document.changepass.retypenewpassword.value ==
document.changepass.newpassword.value)){
            document.changepass.retypenewpassword.blur();
            document.changepass.submit();

    }
}
</script>

<form name="changepass" method="POST" action="changepassword.jsp" onsubmit="return validate();">

<table align="center">
    <tr>
        <td>New Password:</td>
        <td><input type="password" name="newpassword" size="20"
            style="width: 145px" maxlength="10"></td>
    </tr>
    <tr>
        <td>Retype New Password:</td>
        <td><input type="password" name="retypenewpassword" size="20"
            style="width: 144px" maxlength="10"></td>
    </tr>
    <tr>
        <td><input type="submit" value="Change Password" name="operation" ></td>
        <td><input type="reset"></td>
    </tr>
    </table>
</form>

函数验证(){
if((document.changepass.newpassword.value!='')&&
(document.changepass.retypenewpassword.value==
document.changepass.newpassword.value){
document.changepass.retypenewpassword.blur();
document.changepass.submit();
}
}
新密码:
重新键入新密码:
但是当我给出不匹配的条目时,它也会被更改。我的意思是验证函数不会被调用。 plz帮助

希望中
robin

无论发生什么情况,您的表单都将提交,因为您不会在出现错误时从验证函数返回false。应该是:

function validate() {
    var d = document.changepass;
    if((d.newpassword.value != '') && (d.retypenewpassword.value == d.newpassword.value)) {
        return true;
    }
    return false;
}

目前,您没有为
validate()
指定返回值,它被解释为总是返回true,因此表单将被提交。您不需要从函数中调用
submit()
,只要在一切正常的情况下返回true即可。

无论发生什么情况,您的表单都将提交,因为在出现错误时验证函数不会返回false。应该是:

function validate() {
    var d = document.changepass;
    if((d.newpassword.value != '') && (d.retypenewpassword.value == d.newpassword.value)) {
        return true;
    }
    return false;
}

目前,您没有为
validate()
指定返回值,它被解释为总是返回true,因此表单将被提交。您不需要从函数中调用
submit()
,只要在一切正常的情况下返回true即可。

您的
上的
onsubmit
处理程序正在寻找返回值,但
validate
函数没有给出返回值。您不应该在函数中调用
submit()
,而应该根据表单是否验证返回true或false(如果函数返回
false
,这相当于
onsubmit=“false”
,这将取消提交):


上的
onsubmit
处理程序正在查找返回值,但没有从
validate
函数中获得返回值。您不应该在函数中调用
submit()
,而应该根据表单是否验证返回true或false(如果函数返回
false
,这相当于
onsubmit=“false”
,这将取消提交):


您需要使用101010按钮格式化代码。我猜您有一些HTML标记,它们正在被剥离。这与问题无关,但您可以肯定服务器端代码也提供了相同的控件。Javascript验证很容易被跳过,您不能依赖它。您需要使用101010按钮格式化代码。我猜您有一些HTML标记,它们正在被剥离。这与问题无关,但您可以肯定服务器端代码也提供了相同的控件。Javascript验证很容易被跳过,您不能依赖它。如果逻辑错误
((document.changepass.newpassword.value='')| | document.changepass.retypenewpassword.value!=document.changepass.newpassword.value!)
如果逻辑错误
((document.changepass.newpassword.value='')||document.changepass.retypenewpassword.value!=document.changepass.newpassword.value))