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

149
Views
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 answers
Answer question

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 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!