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

152
Visualizações
Confirm dialog box in javascript and html

I´m trying to include a confirmation dialog in my code, but I get stucked while implementing it. I want to add a button to my code that by clicking on it I get a confirmation dialog. Pressing the "yes-option" it should delete data in my database, while pressing the "no-option" should close the dialog box doing nothing else. But actually, when I run my code I get my dialog box and the confirmation yes/no options, but running the "no option" the submit code in html gets trigger too, so that by choosing "yes" or "no" I get the same effect and it delete always the data from my database.

This is my html code:

<form method="POST" action="/delete/prop" >
<p class="card-text h6"> <b>Typology: </b> <%= book.typology %> </p>
<input type="hidden" name="id5" value=<%= book.id %> />
<input type="hidden" name="prop" value= "typology" />

<input type="submit" value="Yes" class="button btn btn-danger" onclick="confirmAction()" />
</form>

And my javascript related to the dialog code:

<script type="text/javascript">
  function confirmAction() {
    let confirmAction = confirm("Are you sure to execute this action?");
    if (confirmAction == true) {
      alert("Action successfully executed");
    } else {
      alert("Action cancelled");
    }
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found the solution in another website posted by @anavega.

She mentioned that I missed the return element in the html.

Here an example to test it :

function confirmAction() {
    let confirmAction = confirm("Are you sure to execute this action?");
    if (confirmAction == true) {
      alert("Action successfully executed");
    } else {
      alert("Action cancelled");
    }
}
<input type="submit" value="Yes" class="button btn btn-danger" onclick="return confirmAction()" />

Thank you for your help!

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