Page 1 of 1

Confirm Delete

Posted: Wed Jan 21, 2009 6:51 pm
by dman779
I need help implementing a confirm delete pop up for a delete function on my script. Here is the php code:

Code: Select all

echo '<td align="center">[<a href="cross_check.php?userID='.$a2['id'].'" class="Ab">Cross Check</a>][<a href="support_reply.php?start_message=new&user_id='.$a2['id'].'#newMess" class="Ab">Message User</a>][<a href="?action=Delete&&id='.$a2['id'].'" class="Ab">Delete</a>]/[<a href="?action=View&&id='.$a2['id'].'" class="Ab">Edit</a>]/'.$Link.'</td>

Can someone please tell me what to add so that when the function delete is clicked a javascript or other pop up comes up and confirms that i want to delete this user.


Thank You!

Re: Confirm Delete

Posted: Wed Jan 21, 2009 8:20 pm
by Burrito

Code: Select all

 
function deleteIt(what)
{
  if(confirm("are you sure you want to delete "+what))
   // do stuff
}
 

Re: Confirm Delete

Posted: Thu Jan 22, 2009 3:08 am
by mattpointblank
Just remember that if the user has javascript disabled, they'll get no warning...

Re: Confirm Delete

Posted: Thu Jan 22, 2009 8:36 am
by Sindarin
I prefer to do it by showing a div,

Delete link goes to index.php?action=confirmdelete&id=$entryid, that shows a div over the entry with Yes and No links.
Yes has link index.php?action=delete&id=$entryid which removes the entry from the database while No just goes to index.php.

Re: Confirm Delete

Posted: Thu Jan 22, 2009 2:42 pm
by dman779
Thanks for your help everyone, I ended up doing this with the code:


adding this script to the code at the top of my page:

Code: Select all

<script type="text/JavaScript">
function confirmDelete()
{
    return confirm("Are you sure you want to delete this user?");
} 
</script>
this is the code that displays functions for my users on my dashboard. I ended up adding

Code: Select all

onclick="return confirmDelete();"
to my original code to call the function. The final code is below.

Code: Select all

echo '<td align="center">[<a href="cross_check.php?userID='.$a2['id'].'" class="Ab">Cross Check</a>][<a href="support_reply.php?start_message=new&user_id='.$a2['id'].'#newMess" class="Ab">Message User</a>][<a href="?action=Delete&&id='.$a2['id'].'" onclick="return confirmDelete();" class="Ab">Delete</a>]/[<a href="?action=View&&id='.$a2['id'].'" class="Ab">Edit</a>]/'.$Link.'</td></tr>';