Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda