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

248
Views
¿Por qué si se ejecuta el bloque y no el bloque else en javascript?

Aprendizaje de HTML, CSS y JavaScript. Me pregunto por qué el siguiente código no funciona incluso cuando ingreso los datos correctos. error.

Aquí está el código:

 <!DOCTYPE html> <html lang="en"> <head> <title>Test</title> </head> <body> Username: <br> <input type="text" name="" id="username"> <br> Password: <br> <input type="text" id="password"> <br> <button onclick="validate();">Submit</button> <script> // verification function validate(){ var a=document.getElementById(username); var b=document.getElementById(password); // even if i enter the correct credentials only the if part runs. if(a!="admin" || b!=1234){ alert("Incorrect username or password.\nRetry Please!"); // opening the same page window.open("jsvalidate.html","_self"); } else{ alert("Welcome" + a); // opening some other page. window.open("new.html","_self"); } } </script> </body> </html>

Y no, no estoy creando una página de validación, sé que debería hacerse con ajax o php, solo me pregunto por qué no funciona. Por favor, dame una explicación para que yo recuerde esto para mi vida. ¡Gracias!

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!