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

113
Views
addEventListener no envió el mensaje de entrada HTML a la consola

Tengo un campo de entrada y un botón en HTML.

 <div class="chat-input" id="chat-input"> <input type="text" id="input-msg" placeholder="Enter message..."/> <button class="send-btn" type="button" id="send-btn"> <img src="send.png" alt="send-btn"> </button> </div>

Creo la constante para la sección de entrada y el botón en el archivo javascript del lado del cliente.

 const user_send =document.querySelector("#send-btn"); const user_msg=document.querySelector("#input-msg");

y agregue el eventlistener en el botón de envío.

 user_send.addEventListener("submit",()=>{ const msg = user_msg.value; console.log(msg); });

Pero no envía el valor a la consola.

También intento con getElementById pero no funciona.

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

0

reemplace addEventListener("submit".. por user_send.addEventListener("click" Cuando el usuario hace clic en el botón, su const obtiene el valor de la entrada.

about 4 years ago · Juan Pablo Isaza Report

0

Prueba esto

 const user_send = document.querySelector("#send-btn"); const user_msg = document.querySelector("#input-msg"); user_send.addEventListener("click", () => { const msg = user_msg.value; console.log(msg); });
 <div class="chat-input" id="chat-input"> <input type="text" id="input-msg" placeholder="Enter message..." /> <button class="send-btn" type="button" id="send-btn"> <img src="send.png" alt="send-btn"> </button> </div>

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!