2

function login() {
  var un = document.getElementById("username").value;
  var pw = document.getElementById("password").value;
  if (un == "admin" && pw == "admin") {
    window.open("TXL.html", '_blank');
    this.window.close();
    return true;
  }
  else {
    alert("FAIL");
    return false;
  }
}
<div class="modal-body">
  <form action="" class="form center-block" onsubmit="login()">
    <div class="form-group">
      <input type="text" id="username" class="form-control input-lg" placeholder="">
    </div>
    <div class="form-group">
      <input type="password" id="password" class="form-control input-lg" placeholder="">
    </div>
    <div class="form-group">
      <button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>
    </div>
  </form>
</div>

The login-window just refresh after submit. And I tried "window.open("TXL.html", '_self');" and it doesn't work,even can't open the new window. I also tried window.location.href=""; ,it still doesn't work. Thanks for reading!

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
Dendi
  • 21
  • 3
  • What is `this.window.close()`? It should probably be `window.close()` or `self.close()`. Still, read this answer http://stackoverflow.com/a/19768082/4477659 – Marc Compte Dec 27 '16 at 10:32

2 Answers2

0

Working fiddle.

You've to add return in the onsubmit event :

<form action="" class="form center-block" onsubmit="return login()">

Hope this helps.

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
0

<form action="" class="form center-block" onsubmit="login()">

Maybe i should use 'onclick' instead of 'onsubmit'?

Dendi
  • 21
  • 3