Home > database >  Trying to redirect page after login validation using javascript and html, won't work
Trying to redirect page after login validation using javascript and html, won't work

Time:05-27

So just starting coding in html and js, need some help as to why the page isn't redirecting after validation. The page just resets after logging in, and i'm trying to get it to redirect to login.html. Any help please?

DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Task Manager</title>
    <link rel="stylesheet" href="style.css">
    <script src ="login.js"> </script>
  </head>
  <body>
    <div >
      <h1>Task Manager</h1>
      <form method="post">
        <div  >
          <input type="text" required name="" id="username">
          <span></span>
          <label>Username</label>
        </div>
        <div >
          <input type="password" name=""  id="password">
          <span></span>
          <label>Password</label>
        </div>
        <div >Forgot Password?</div>
        <input type="submit" name="" value="Login"  onclick="validate()">
        <div >
          Not a member? <a href="#">Signup</a>
        </div>
      </form>
    </div>

  </body>
</html>

Javascript:

function validate()
{
var username=document.getElementById("username").value;
var password=document.getElementById("password").value;
if(username=="admin"&& password=="user")

{

    alert("login succesfully");
    window.location.href = "./todo.html";

    return false;
    
}
else
{
    alert("login failed");
    return false;


}

}

CodePudding user response:

Your problem is in the java script in the return part so I don't remember exactly how to end the redirect in true

CodePudding user response:

You can change window.location.href = "./todo.html"; to window.location = "./todo.html";

  • Related