Confirm Delete

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dman779
Forum Newbie
Posts: 6
Joined: Wed Jan 21, 2009 6:47 pm

Confirm Delete

Post 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!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: Confirm Delete

Post by Burrito »

Code: Select all

 
function deleteIt(what)
{
  if(confirm("are you sure you want to delete "+what))
   // do stuff
}
 
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: Confirm Delete

Post by mattpointblank »

Just remember that if the user has javascript disabled, they'll get no warning...
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: Confirm Delete

Post 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.
dman779
Forum Newbie
Posts: 6
Joined: Wed Jan 21, 2009 6:47 pm

Re: Confirm Delete

Post 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>';
Post Reply