shortysbest Posted November 29, 2010 Share Posted November 29, 2010 I have a function that is running twice because you have to click on the same div twice to delete a comment (the first click changes the text to confirm that you want to delete it, the second one deletes it) I can't seem to figure out the best way to atleast stop part of the code from running twice. I have commented parts of it to give you an idea of what i need to happen function delete_comment(rid) { var result = rid.split("-"); var id = result[1]; var post_id = result[2]; /////On first click div txt changes from "X" to "Delete", and the css changes some. $("#"+rid).html("Delete"); $("#"+rid).css({backgroundColor: "#FFE1E1", color: "#333"}); ///////On Second click the ajax runs (this is the part of the code that i can't have run twice) $('#'+rid).click(function() { $("#"+rid).html("Deleting.."); $.ajax({ type: "POST", url: "ajaxpages/php/delete_comment.php", data: 'sub_comment_id='+id, cache: false, success: function(html){ $("#sub-comment"+id).slideUp("fast"); ////this code below is the code i cannot have running twice, it is suppose to subtract just 1 from the hidden field for another function of my website, but since the code is running twice it subtracts 2 from it, It is only suppose to subtract 1 per comment that is deleted. var valu = document.getElementById('value'+post_id); valu.value = parseInt(valu.value) - 1; } }); }); } Link to comment https://forums.phpfreaks.com/topic/220094-best-way-to-stop-this-function-from-running-twice/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.