Page 1 of 1

Confirmation box when clicking on a delete link...

Posted: Tue Apr 19, 2005 4:50 am
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>

Posted: Tue Apr 19, 2005 4:54 am
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

Posted: Tue Apr 19, 2005 4:57 am
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;>

Posted: Tue Apr 19, 2005 5:18 am
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;>

Posted: Tue Apr 19, 2005 5:24 am
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??

Posted: Tue Apr 19, 2005 7:13 am
by feyd
checkboxes! :)

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