Javascript表单验证不适用于注册弹出表单

时间:2019-11-13 23:47:13

标签: javascript php html validation

***我的注册表格代码

function validation1() {
  var password1 = document.getElementById('password1').value;
  var password2 = document.getElementById('password2').value;

  if (password1 == password2) {
    return true;
  } else {
    alert("password must be same!");
    return false;
  }
}
<div class="container4" id="myForm1">
  <form action="Home.html" id="myForm1" class="form-container1" method="post" onsubmit="return validation1();">
    <?php include('errors.php'); ?>
    <h1>Register</h1>
    <p>Please fill in this form to create an account.</p>
    <hr>

    <label for="email"><b>Email</b></label>
    <input type="email" placeholder="Enter Email" id="email" name="email" required>

    <label for="psw"><b>Password</b></label>
    <input type="password" placeholder="Enter Password" id="password1" name="password1" required>

    <label for="psw-repeat"><b>Repeat Password</b></label>
    <input type="password" placeholder="Repeat Password" id="password2" name="password2" required>
    <hr>
    <p>By creating an account you agree to our <a href="#">Terms & Privacy</a>.</p>

    <button type="submit" class="btn2">Register</button><br><br>
    <button type="button" class="btn cancel" onclick="closeForm1()">Close</button>
  </form>
</div>

我在同一页面上有一个类似的登录弹出窗口。它可以正确执行验证,但对于注册形式,“返回true”值无效。

0 个答案:

没有答案