Delete confirmation

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
3.14
Forum Commoner
Posts: 28
Joined: Mon Sep 08, 2003 12:17 am

Delete confirmation

Post by 3.14 »

Code: Select all

<?php
<a href="<?= $_SERVER['PHP_SELF'] ?>?level=<?= $line['level'] ?>&code=<?= $line['code'] ?>" onclick="return confirm('Are you sure you want to delete this?')">delete</a>
?>
This brings up a message box saying 'Are you sure you want to delete this?' Ok, Cancel. However, if I click on either ok or cancel it deletes. How can I make it so that cancel will actually stop the process?
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

A link does not cares about the data returned from the onclick= attribute. You must set the href= attribute to a javascript function that does

Code: Select all

document.location= "<?= $_SERVER&#1111;'PHP_SELF'] ?>?level=" + level + "&code=" + code;
and pass the $line['level'] and $line['code'] as level and code parameters for this function. Inside this function you deal with the confirmation before changing the document.location.
Post Reply