Page 1 of 1

Delete confirmation

Posted: Thu Oct 30, 2003 11:01 pm
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?

Posted: Thu Oct 30, 2003 11:24 pm
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.