Confirmation box when clicking on a delete link...

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
vittelite
Forum Newbie
Posts: 12
Joined: Tue Mar 08, 2005 9:23 am

Confirmation box when clicking on a delete link...

Post by vittelite »

Hi,
is there any way of making a confirmation window come up to select Yes or No when clicking on a delete link to delete a record? Please bear in mind I am refering to a link and not a form button. Thanks. For example if I have the following code:

Code: Select all

echo "<tr>
<td>" . stripslashes($row['user_id']) . "</td>
<td>" . stripslashes($row['first_name']) . "\n" . stripslashes($row['last_name']) . "</td>
<td>" . stripslashes($row['email']) . "</td>
<td>" . stripslashes($row['URN']) . "</td>
<td>" . stripslashes($row['registration_date']) . "</td>
<td align><a href=\"delete_user.php?user_id={$row['user_id']}\">Delete</a></td>
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Code: Select all

<SCRIPT language=&quote;JavaScript&quote;>
<!--
function ConfirmDelete()
{
 var ConfirmReq = confirm(&quote;Are you sure you want to delete this item?&quote;);
 if (ConfirmReq == true)
 {
   // send to the &quote;process.php&quote; page with a $delete=1 var to confirm deletion 
 }
 else
 {
   // do something else or preferably nothing
 }
}
//-->
</SCRIPT>
just an idea
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

thought i would add this for "completeness" sake (not even a word :oops: )

anyway.. to call the confirm box....

Code: Select all

<input type=&quote;button&quote; value=&quote;delete&quote; OnClick=&quote;ConfirmDelete()&quote;>
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Beware, if JavaSCript is diabled, there isn't gonna pop up any confirmation box ;)
Also, you could do this (a little bit easier):

Code: Select all

<input type=&quote;submit&quote; value=&quote;delete&quote; OnClick=&quote;return confirm('Are you sure you want to delete this item?');&quote;>
vittelite
Forum Newbie
Posts: 12
Joined: Tue Mar 08, 2005 9:23 am

Post by vittelite »

Thanks for the info, but I am listing more than one users per page. Any way I can get a Delete button on the page for each user? And how is it possible to link that button to delete a specific user on the list??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

checkboxes! :)

Use a form processor (php) to do the confirmation and deletion. Screw Javascript. ;)
Post Reply