In HTML, delete_icon
is an image class in which if I click it, the email id gets deleted without any confirmation message. I want to add a popup to display when delete_icon
is clicked. The popup mentioned above should open and if yes
is clicked, the instance should get deleted, otherwise it should return the same. How can I achieve this in jQuery
or JavaScript
?
Asked
Active
Viewed 1.6k times
5

Monk L
- 3,358
- 9
- 26
- 41
-
It will be better that you handle it using the confirmation box plugin such as Zebra Dialog or the Dialog in jquery UI. ACcordingly you can handle the response on the button click index. – Akhilesh Sharma Jun 11 '13 at 12:26
-
Please refer to the following link as there will be lot things that are to be handled manually http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/ – Akhilesh Sharma Jun 11 '13 at 12:31
-
@MonkL `jQuery` is an additionnal library... If you want it simple why didn't you do it in **pure JS**? – Jeff Noel Jun 11 '13 at 12:33
-
1Possible duplicate of [How to show a confirm message before delete?](http://stackoverflow.com/questions/9139075/how-to-show-a-confirm-message-before-delete) , I don't think this is Django specific. – Ciro Santilli OurBigBook.com May 10 '16 at 09:22
3 Answers
3
You can better use as follows
<a href="url_to_delete" onclick="return confirm('Are you sure want to dele');">Delete</a>

Raghav Rach
- 4,875
- 2
- 16
- 16
1
Hmm. You do this with simple javascript.
<script type="text/javascript">
function deleteImage(x){
var conf = confirm("Are you sure you want to delete this image?");
if(conf == true){
alert("OK... you chose to proceed with deletion of "+x);
}
}
</script>
Using the default browser confirmation box. And this is the example use of the function.
<input name="myBtn" type="button" onClick="deleteImage('images/pic.jpg')" value="Delete Image">

Edwin Lunando
- 2,726
- 3
- 24
- 33
-
I am not interested in default browser confirmation box,because in my app,using popup box which is with pure white background,so including default will look ugly,so i try to go for customization,can you tell me how to customize it in my case.I am developing in django web framework,i updated my js code and html. – Monk L Jun 13 '13 at 04:57
0
try this
$('.delete_icon').click(function(){
if(confirm('Are sure want to delete record?'))
{
var obj = $(this)
var csrf_token = "{{ csrf_token }}";
var email = $(this).attr('value');
var id = $(this).attr('id');
$.ajax({
data:{csrfmiddlewaretoken: csrf_token,id:id,cancel_email:email},
type:'POST',
url: '/report/notification/',
cache:false,
success: function(response) {
$(obj).parent('p').remove();
return false;
}
});
});
}
});

sangram parmar
- 8,462
- 2
- 23
- 47
-
You might want to add some explanation before your code or comments into it, in case some people unfamiliar with the code see it. – Jeff Noel Jun 11 '13 at 12:31