Generally When you perform the CRUD operations on any application . To warn a user when user trying to remove / delete anything from the displayed data from the database.
I.e " Are you sure you want to delete this item ? ".
When user click on the remove link it will pop up the confirm message . Here user press on the ok key then that item will be removed otherwise nothing will happen.
This can be done in two different ways
JavaScript Function
Function calling
Second way
Output
Delete
I.e " Are you sure you want to delete this item ? ".
When user click on the remove link it will pop up the confirm message . Here user press on the ok key then that item will be removed otherwise nothing will happen.
This can be done in two different ways
- You can create the JavaScript function and call this function from the anchor href tag
- You can directly call the confirm function from the on click event.
JavaScript Function
1 2 3 4 5 6 7 | <script> function confirmDelete(delUrl) { if (confirm( "Are you sure you want to delete this item" )) { document.location = delUrl; } } </script> |
1 | < a href = "javascript:confirmDelete('delete.php?id=1')" >Delete</ a > |
1 | < a href = "delete.php?id=1" onclick = "return confirm('Are you sure you want to delete this item ?')" >Delete</ a > |
* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff