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

117
Views
addEventListener didn't send the HTML input message to console

I Have input field and button in 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>

I create the constant for input section and button in client side javascript file.

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

and add the eventlistener in send button.

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

But it does not send the value to the console.

I also try by getElementById but it doesnot work.

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

0

replace addEventListener("submit".. by user_send.addEventListener("click" When the user click on the button, your const get the value of the input.

about 4 years ago · Juan Pablo Isaza Report

0

Try this

    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!