Jump to content

best way to stop this function from running twice?


shortysbest

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.