验证弹出窗口,然后打开另一个弹出窗口

时间:2016-08-08 18:27:23

标签: javascript twitter-bootstrap popup

我正在使用bootstrap创建一个弹出注册表单。一旦用户点击提交并且它已经过验证,我想关闭该弹出窗口并打开另一个说谢谢。我尝试在popupvalidation.js中使用.modal('show'),但这似乎不起作用。所有这一切都是同时开放的。

以下是代码:

的index.php

<form name="popup" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" onsubmit="return popupValidation();" method="post">
                  <div class="row">
                    <input name="firstName" type="text" class="form-control" id="inputFirstName" placeholder="First Name">
                    <input name="lastName" type="text" class="form-control" id="inputLastName" placeholder="Last Name">
                  </div>
                  <div class="row">
                    <input name="email" type="email" class="form-control" id="inputEmail" placeholder="youremail@email.com">
                  </div>
                  <div class="row">
                    <input name="password" type="password" class="form-control" id="inputPassword" placeholder="password">
                  </div>
                  <div class="row">
                    <input name="repeatPass" type="password" class="form-control" id="retypePassword" placeholder="Retype password">
                  </div>
                  <div class="row">
                    <input name="trainer" type="checkbox"/> Sign up as trainer
                  </div>
                  <div class="modal-footer popup-footer">
                    <p id="error">Please make sure all fields are filled out</p>
                    <input type="submit" class="btn btn-default submit" value="Register">
                  </div>
                </form>

popupvalidation.js

function popupValidation() {
    var fname = document.forms["popup"]["firstName"].value;
    var lname = document.forms["popup"]["lastName"].value;
    var pass = document.forms["popup"]["password"].value;
    var repass = document.forms["popup"]["repeatPass"].value;
    var email = document.forms["popup"]["email"].value;

    if (fname==null || fname=="") {
      document.getElementById("inputFirstName").focus();
      document.getElementById("error").innerHTML= 'Please enter your First Name';
      document.getElementById("error").style.display = 'block';
      return false;
    }
    if (lname==null || lname=="") {
      document.getElementById("inputLastName").focus();
      document.getElementById("error").innerHTML= 'Please enter your Last Name';
      document.getElementById("error").style.display = 'block';
      return false;
    }
    if (email==null || email=="") {
      document.getElementById("inputEmail").focus();
      document.getElementById("error").innerHTML= 'Please enter a valid email';
      document.getElementById("error").style.display = 'block';
      return false;
    }
    if (pass==null || pass=="") {
      document.getElementById("inputPassword").focus();
      document.getElementById("error").innerHTML= 'Please enter a password';
      document.getElementById("error").style.display = 'block';
      return false;
    }
    if (repass==null || repass=="") {
      document.getElementById("retypePassword").focus();
      document.getElementById("error").innerHTML= 'Please retype password';
      document.getElementById("error").style.display = 'block';
      return false;
    }
    if (repass!=pass) {
      document.getElementById("retypePassword").focus();
      document.getElementById("error").innerHTML= 'Passwords do not match';
      document.getElementById("error").style.display = 'block';
      return false;
    }
  }

0 个答案:

没有答案