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

127
Views
I want help in adding an event listener

I'm a django developer not good at javascript. I have a django template i really want to use Javascript for. i tried reading online for help but i'm not understanding

I want to add an addEventlistener to this code below

<div class="box-element hidden" id="request-info">
        <button id="send-payment">Send request</button>

Also, I want it to display a response when submitted. Response like "Request sent". Please I know about console.log, I don't want it in console.log.

I know JS is really good at this.

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

0

So presumably you want to add an event listener to the button so that it submits when clicked. You can go about that by adding an event listener to the element between two script tags <script></script> or in your .js file. The code would look like:

document.getElementById("send-payment").addEventListener("click", function() {
     /*
          Action Here...
     */
     alert("Request Sent!") // This will throw up an alert to the user.
})

From what I gather this should be a simple solution, you can find more documentation here: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

about 4 years ago · Juan Pablo Isaza Report

0

You need a space to display the message "Request sent". Here I use the p tag

<div class="box-element hidden" id="request-info">
  <button id="send-payment">Send request</button>
  <p id="response"></p>
<script>
 document.getElementById("send-payment").addEventListener("click", function(){
 document.getElementById("response").innerHTML = "Request sent";
})
</script>

Here is the link on w3schools: https://www.w3schools.com/jsref/met_document_addeventlistener.asp

about 4 years ago · Juan Pablo Isaza Report

0

Make this

const button = document.getElementById("send-payment");

button.addEventListener("click", function() {
  document.getElementById("request-info").style.display = "block";
})
#request-info {
  display: none;
  color: green;
  font-size: 12px;
  margin-bottom: 10px;
}
<div id="request-info">Request sent</div>
<button id="send-payment">Send request</button>

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!