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

170
Views
TypeError no capturado (en promesa): no se pueden establecer propiedades de nulo (estableciendo 'onclick') en users.js: 18

Estoy tratando de crear un formulario de inicio de sesión mediante el cual los datos de los usuarios se obtienen a través de una solicitud de obtención y se verifican con el siguiente código javascript:

 fetch('./login.php', { method: 'GET' }) .then((res) => res.json()) .then(res => { let user = [] for (let data of res){ user.push({ email: "'"+data.email+"'", password : "'"+data.password+"'" }) } let button = document.querySelector('.btn btn-danger submit'); function login(){ let email = document.getElementById('useremail').value; let password = document.getElementById('userpassword').value; for(i=0; i < user.length; i++){ if(email == user[i].email && password == user[i].password){ window.location = "home.html"; } } } button.onclick = login(); })

Cada vez que reviso la consola me muestra el error en el título. ¿Hay algo mal con la forma en que estoy tratando de hacer esto?

Aquí está mi código HTML para el formulario (usando bootstrap):

 <form action="" id="loginform"> <div class="mb-3"> <label for="useremail" class="form-label">Email:</label> <input type="email" class="form-control" id="useremail" aria-describedby="Email" name="useremail" required> </div> <div class="mb-3"> <label for="userpassword" class="form-label">Password:</label> <input type="password" class="form-control" id="userpassword" aria-describedby="Password" name="userpassword" required> </div> <button class="btn btn-danger submit" type="submit">Login</button> <div class="row mt-3"> <a href="register.html" class="text-decoration-none text-decoration-underline text-dark fst-italic">Don't have an account? Register Here.</a> </div> </form>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

let button = document.querySelector('.btn btn-danger submit'); Está Mal. Seleccionará una clase de submit dentro btn-danger dentro de una clase btn .

Necesita let button = document.querySelector('.btn.btn-danger.submit'); . O, en mi opinión, agregue una id al botón y utilícela.

Además, estoy bastante seguro de que button.onclick = login(); sería simplemente button.onclick = login; ya que no necesita ejecutar la función de inmediato, sino vincular la función al onclick .

about 4 years ago · Santiago Trujillo 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!