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

365
Views
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
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!