Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda