Reputation: 19
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>
Upvotes: 0
Views: 2068
Reputation: 75
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.
Upvotes: 1