Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery delete confirmation box

Tags:

jquery

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....

like image 629
shanish Avatar asked Apr 25 '12 05:04

shanish


4 Answers

You need to add confirm() to your deleteItem();

function deleteItem() {
    if (confirm("Are you sure?")) {
        // your deletion code
    }
    return false;
}
like image 84
Māris Kiseļovs Avatar answered Oct 22 '22 18:10

Māris Kiseļovs


$(document).ready(function(){
  $(".del").click(function(){
    if (!confirm("Do you want to delete")){
      return false;
    }
  });
});
like image 39
Shashank Hegde Avatar answered Oct 22 '22 19:10

Shashank Hegde


I used this:

<a href="url/to/delete.asp" onclick="return confirm(' you want to delete?');">Delete</a>
like image 15
Umair Hamid Avatar answered Oct 22 '22 19:10

Umair Hamid


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.

like image 11
Chandresh M Avatar answered Oct 22 '22 19:10

Chandresh M