单击我的网页中的文本框后显示错误的消息。 [英] The wrong message is being displayed after clicking out of the text box in my webpage.

查看:86
本文介绍了单击我的网页中的文本框后显示错误的消息。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了几个函数来检查两个密码是否相等。当我单击验证密码框时,它应显示密码匹配或请再次输入密码,因为两个密码不匹配,具体取决于密码是否相等。但是,当我键入两个相同的密码并单击验证密码文本框时,该消息显示请再次输入密码,因为这两个密码不匹配,即使这两个密码完全相同。我在这里做错了什么?



我在这个网页上使用了password.js文件和setpassword.html文件。



我的password.js文件是:



I wrote several functions to check if the two passwords are equal. When I click out of the "verify password" box, it should either display "The passwords match" or "Please enter your password again because the two passwords don't match" depending on whether or not the passwords are equal to each other. However, when I type in two identical passwords and I click out of the "verify password" text box, the message displays "Please enter your password again because the two passwords don't match" even though the two passwords are completely identical. What am I doing wrong here?

I am using a password.js file and a setpassword.html file for this webpage.

My password.js file is:

var password1 = document.getElementById("txtPassword").value;
var verifypassword = document.getElementById("txtPWVerified").value;

var verifypasswordclick = document.getElementById("txtPWVerified");

function verifypassword1() {
    if(password1 == verifypassword && password1 != "" && verifypasword != "") {
        alert('The passwords match');
    }
    else if(password1 != verifypassword || password1 == "" || verifypasword == "") {
        alert("Please enter your password again because the two passwords don't match");
    }
}

verifypasswordclick.onblur = function() {
    verifypassword1;
};





我的setpassword.html文件是:





My setpassword.html file is:

<!DOCTYPE html>
<!-- H5FormValidation.html -->
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Register Here</title>
</head>

<body>
  <h2>Register Here</h2>

  <form id="formTest" method="get" action="processData">
    <table>

    <tr>
      <td><label for="txtEmail">Email<span class="required">*</span></label></td>
      <td><input type="email" id="txtEmail" name="email" required></td>
    </tr>
    <tr>
      <td><label for="txtPassword">Password<span class="required">*</span></label></td>
      <td><input type="password" id="txtPassword" name="password" required></td>
    </tr>
    <tr>
      <td><label for="txtPWVerified">Verify Password<span class="required">*</span></label></td>
      <td><input type="password" id="txtPWVerified" name="pwVerified" required></td>
    </tr>

    <tr>
      <td> </td>
      <td>
          <input type="reset" value="CLEAR" id="btnReset"></td>
    </tr>
    </table>
  </form>
 <script src = "password.js"></script>
</body>
</html>





我的尝试:



我已经尝试调试它30分钟但没有任何效果。



What I have tried:

I have tried debugging it for 30 minutes but nothing works.

推荐答案

尝试替换

try to replace
var password1 = document.getElementById("txtPassword").value;
var verifypassword = document.getElementById("txtPWVerified").value;
 
var verifypasswordclick = document.getElementById("txtPWVerified");
 
function verifypassword1() {
    if(password1 == verifypassword && password1 != "" && verifypasword != "") {
        alert('The passwords match');
    }
    else if(password1 != verifypassword || password1 == "" || verifypasword == "") {
        alert("Please enter your password again because the two passwords don't match");
    }
}
 
verifypasswordclick.onblur = function() {
    verifypassword1;
};



类似


with something like

function verifypassword1() {
    var password1 = document.getElementById("txtPassword").value;
    var verifypassword = document.getElementById("txtPWVerified").value;
 
    var verifypasswordclick = document.getElementById("txtPWVerified");
 
    if(password1 == verifypassword && password1 != "" && verifypasword != "") {
        alert('The passwords match');
    }
    else if(password1 != verifypassword || password1 == "" || verifypasword == "") {
        alert("Please enter your password again because the two passwords don't match");
    }
}
 
verifypasswordclick.onblur = function() {
    verifypassword1;
};



您的问题是用于检查密码的变量反映了加载时的输入值,而不是验证时的输入值。 />


建议:你应该学习调试器的实际用法,因为对变量值的简单检查会告诉你出了什么问题。


Your problem is that the variables used to check the password reflect the input values at load time instead of the input values at verify time.

Advice: You should learn the real usage of the debugger, because a simple inspection of the values of the variables would have told you what is wrong.


这篇关于单击我的网页中的文本框后显示错误的消息。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆