Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

422
Views
Trying to redirect page after login validation using javascript and html, won't work

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 class="center">
      <h1>Task Manager</h1>
      <form method="post">
        <div  class="txt_field">
          <input type="text" required name="" id="username">
          <span></span>
          <label>Username</label>
        </div>
        <div class="txt_field">
          <input type="password" name=""  id="password">
          <span></span>
          <label>Password</label>
        </div>
        <div class="pass">Forgot Password?</div>
        <input type="submit" name="" value="Login"  onclick="validate()">
        <div class="signup_link">
          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;


}

}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!