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

155
Views
Necesita que la salida de las entradas se inserte en <div>

Estoy tratando de que las entradas del usuario se envíen como un mensaje a un <div> presionando el botón después de confirmar que todas las entradas están completas y que se ha ingresado la contraseña correcta. Esa parte funciona bien pero mi forEach no funciona:

Si el usuario ha ingresado un valor numérico inferior a 18, quiero un if eso escribe a través de push "Su nombre es UName y tiene años de Age , no es mayor de edad" , o el mismo resultado que el anterior pero finalizando con "...eres mayor de edad" .

¿Alguna idea de cómo debo seguir?

 let nameElement = document.getElementById("UNameInput"); let faultElement = document.getElementById("errorOutput"); let ageElement = document.getElementById("AgeInput"); let clickElement = document.getElementById("button"); let passwordElement = document.getElementById("PasswordInput"); clickElement.addEventListener("click", function(e) { let feedback = []; if (UNameInput.value === '' || UNameInput.value === null) { feedback.push('Name input missing') } if (AgeInput.value === '' || AgeInput.value === null) { feedback.push('Age input missing') } else if (PasswordInput.value !== 'IHM') { feedback.push('Password is not valid') } else { feedback.forEach((item, i) => { if (item.AgeInput < 18) { feedback.push("You are not of not legal age") } else { feedback.push(" You are of legal age ") } }); } if (feedback.length > 0) { e.preventDefault() faultElement.innerText = feedback.join(", ") } });
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="JSny.js" defer></script> </head> <body> <div id="errorOutput"></div> <p id="output"></p> <div> <label for="UNameInput">Name Input</label> <input id="UNameInput" name="name" type="text"> </div> <div> <label for="AgeInput">Age Input</label> <input id="AgeInput" name="age" type="number"> </div> <div> <label for="PasswordInput">Password Input</label> <input id="PasswordInput" name="password" type="password"> </div> <button id="button">Submit</button> </body> </html>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Está utilizando AgeInput en lugar de ageElement en la instrucción if.

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!