I am trying to update the JavaScript confirm() action to use SweetAlert . My code currently looks something like this:
<a href="/delete.php?id=100" onClick="return confirm('Are you sure ?');" >Delete</a>
This awaits confirmation from the user before going to the delete page. I would like to use this example from SweetAlert to ask the user to confirm before deleting:
swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, delete it!", cancelButtonText: "No, cancel plx!", closeOnConfirm: false, closeOnCancel: false }, function(isConfirm){ if (isConfirm) { swal("Deleted!", "Your imaginary file has been deleted.", "success"); } else { swal("Cancelled", "Your imaginary file is safe :)", "error"); } });
Everything I tried failed. When the first warning is displayed, the page went ahead, deleted the item and was updated before the user even clicked on the warning buttons. How to make the page wait for user input?
Any help would be greatly appreciated.
javascript sweetalert
dmeehan
source share