In my jQuery am displaying my results in a table formatted output, a part of my jQuery is
<td class='close' onclick='deleteItem(#ITEMID,#ITEMNAME)'></td>
here "close"
is a CSS class and in this class I have cross mark image, if I click this cross mark the function(deleteItem) will be fired.
here what I want to do is if I click this cross mark a "delete confirmation box"
should pop up and if I click yes this onclick event should fire, else if I click No nothing should happen.
How can I achieve this, can anyone help me....
You need to add confirm() to your deleteItem();
function deleteItem() {
if (confirm("Are you sure?")) {
// your deletion code
}
return false;
}
$(document).ready(function(){
$(".del").click(function(){
if (!confirm("Do you want to delete")){
return false;
}
});
});
I used this:
<a href="url/to/delete.asp" onclick="return confirm(' you want to delete?');">Delete</a>
Try with below code:
$('.close').click(function(){
var checkstr = confirm('are you sure you want to delete this?');
if(checkstr == true){
// do your code
}else{
return false;
}
});
OR
function deleteItem(){
var checkstr = confirm('are you sure you want to delete this?');
if(checkstr == true){
// do your code
}else{
return false;
}
}
This may work for you..
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With