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

188
Views
TypeError no detectado: no se pueden leer las propiedades de nulo (leyendo 'valor') javascript

Hola, estoy tratando de crear un programa de inicio de sesión que autentique los nombres de usuario solo, de modo que cuando intento pasar la entrada del usuario de html a javascript, lo detecta como nulo. ¿Alguien sabe por qué? Me da este mensaje de error: Login2.js:12

 Uncaught TypeError: Cannot read properties of null (reading 'value') at HTMLButtonElement.document.getElementById.onclick (Login2.js:12:55)

HTML:

 <!DOCTYPE html> <html> <head> <title>StudySkillsApp Log-in</title> </head> <body> <label><b>Username:</b></label> <input placeholder="Enter Username" id={"myText"}> <button type="button" id="myButton"> SIGN IN </button> <script src="Login2.js"> </script> </body> </html>

Y Login2.js (javascript es):

 if(document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', afterLoaded); } else { //The DOMContentLoaded event has already fired. Just run the code. afterLoaded(); } function afterLoaded(){ //Your initialization code goes here. This is from where your code should start // document.readyState === "complete") document.getElementById("myButton").onclick = function(){ var myName = document.getElementById("myText").value; console.log(myName); } };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe eliminar {} corchetes de su código HTML. En la etiqueta de entrada, reemplace id={"myText"} con id="myText"

 <input placeholder="Enter Username" id="myText">

Solucionará el problema.

about 4 years ago · Juan Pablo Isaza 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!