Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

366
Vistas
How to move to another html page after validating the password in javascript?

There are two html pages, the index.html and bankPage.html, I am trying to validate the user using a password on index.html and then if the password is right, he moves to bankPage.html page. With window.location(or location) I am able to move to bankPage.HTML but after moving to the HTML page I get a TypeError becoz the button that I selected holds a value null in bankPage.html and the button is defined in index.html.

The error I get is- Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')

Here is the code

//just an array that holds the user info in objects(array of objects)
const accounts = [account1, account2, account3, account4];

const btnLogin = document.querySelector('.login__button');
const inputLoginUsername = document.querySelector('.login__input--user');
const inputLoginPassword = document.querySelector('.login__input--password');

// Even handlers for logging in from the index page to the bank page

let currentAccount;

btnLogin.addEventListener('click', function (e) {
  e.preventDefault();

  currentAccount = accounts.find(function (acc) {
    return acc.owner === inputLoginUsername.value;
  });

  if (currentAccount?.password === inputLoginPassword.value) {
    //send to another page
    window.location = 'bankPage.html';
    
  }
});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda