Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

435
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda