Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variables?

Status
Not open for further replies.

JohnnyT

Programmer
Jul 18, 2001
167
GB
Hi

I have the following function (I've slimmed it down for clarity):


function display_ability_to_delete($comment_ID) {
?>
<form action="" method="post" id="commentform">
<div class="inner">

<script type="text/javascript">
function mydelete(comment_ID){
var comment = 'Sure you want to delete this ID- '+comment_ID+
echo '<input type="button" class="prev btn" onclick="return confirm_delete();" class="btn" value="Yes" />';
echo '<input type="button" class="prev btn" onclick="return do_not_delete();" class="btn" value="No" />';

jQuery('ul.commentlist').append(comment);
jQuery('#commentform .inner, #commentform .prev.btn').css({display:'none'});

return false;
}


function do_not_delete(){
jQuery('#comment-preview').remove();
jQuery('#commentform .inner, #commentform .prev.btn').css({display:'block'});
}


</script>
<input type="button" class="prev btn" onclick="return mydelete(<?php echo $comment_ID; ?>);" class="btn" value="Delete" />


</form>

<?php
}


Basically this function is called as some comments are looped through in the database. Next to each comment it puts a "Delete" button.

I'm wanting to write a function that will "pop in" a confirm Yes / No box when they click Delete and also remove the Delete button.

At the moment the function works but it only removes the first Delete button. I need it to remove the Delete button that corresponds to the comment_ID that is passed to the function.

I really really new to Javascript so I could do with some pointers.

What I want to do in laymans terms is:
Change the following line in mydelete():
jQuery('#commentform .inner, #commentform .prev.btn').css({display:'none'});

.. To..
jQuery('#commentform .inner, #commentform .prev.btn'.'delete button number {comment_ID}').css({display:'none'});

Or something like that.. then somehow write the comment_ID into the Delete button:
<input type="button" CLASS="delete button number <?php echo $comment_ID"> class="prev btn" onclick="return mydelete(<?php echo $comment_ID; ?>);" class="btn" value="Delete" />

I hope that I'm making myself clear enough?

Any ideas how to achieve this?

Many thanks for any light you can shed on this

Cheers

John ;-)

I don't make mistakes, I'm merely beta-testing life.
 
Think I've cracked it....

jQuery('#comment-'+comment_ID).append(comment);
jQuery('#delete-'+comment_ID).css({display:'none'});

... and then...
<input type="button" id="delete-<?php echo $comment_ID; ?>" class="prev btn" onclick="return mydelete(<?php echo $comment_ID; ?>);" class="btn" value="Delete" />

It seems to be working so far...

Cheers

John ;-)

I don't make mistakes, I'm merely beta-testing life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top