Confirm Box Before Delete Item using jquery
When we will click on delete recorded, after then will open the confirm box and will ask you, are you sure delete this record. that time this tutorial help you.
This is a way of ensuring that items are not accidentally deleted, or the wrong item deleted by mistake. When clicked on the link, then open the confirmation box. if the user selects ‘ok’ then delete is done. if the user selects on ‘no’ or ‘cancel’ then not delete records..
See below example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // first example <a href="delete.php?delete_id=<?php echo $row['id'];?>" onclick="return confirm('Are you sure you want to delete this item?');">Delete</a> // second example <a href="delete.php?delete_id=<?php echo $row['id'];?>" class="delete" data-confirm="Are you sure to delete this item?">Delete</a> $('.delete').on("click", function (e) { e.preventDefault(); var choice = confirm($(this).attr('data-confirm')); if (choice) { window.location.href = $(this).attr('href'); } }); |
Please follow and like us: