0

Please, help me. I want to display confirmation box for delete action. If the user click okay then it will proceed. But if the user click cancel, it cancel the delete operation or go back to the same page. I did the code in javascript but it's not working. when I clicked on cancel on confirmation alert it still proceed to delete action.

  function confirmation() {
    if (confirm("Are you sure you want to delete the reservation?"))
      return true;
    else
      return false;
  }
<td>
  <a href="updateStaffServlet?action=update&sID=<c:out value=" ${staff.staffID} "/>"class="btn btn-icons btn-rounded btn-light">
    <i class="fa fa-pencil"></i>
  </a>
  <a onclick="confirmation()" href="deleteStaffServlet?action=delete&sID=<c:out value=" ${staff.staffID} "/>" id="dltbtn" class="btn btn-icons btn-rounded btn-light">
    <i class="fa fa-user-times"></i>
  </a>
</td>

2
  • Your code is too complex. It can't reproduce !!! Jan 26, 2021 at 8:07
  • Your confirmation function only returns a boolean value and you are not using it anywhere
    – misha1109
    Jan 26, 2021 at 8:10

1 Answer 1

1

this is not the best way but you can pass url to your confirmation function and if user confirmed, redirect him.

  function confirmation(url) {
    if (confirm("Are you sure you want to delete the reservation?"))
      location.replace(url);
  
  }
<td>
  <a href="updateStaffServlet?action=update&sID=<c:out" value=" ${staff.staffID} " class="btn btn-icons btn-rounded btn-light">
    <i class="fa fa-pencil"></i>
update link
  </a>
  <a onclick="confirmation('deleteStaffServlet?action=delete&sID=<c:out')" value=" ${staff.staffID} " id="dltbtn" class="btn btn-icons btn-rounded btn-light">
    <i class="fa fa-user-times"></i>
delete link
  </a>
</td>

but i recommend you learn basics about ajax and send delete request without redirecting page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.