Delete Warning

Javascript that alert users when clicking on sensitive links (like delete or update links). You can customize the message with option to continue or cancel. Works great with PHP, ASP, and Perl administration sites.
Introduction:

This javascript registers an event handler to a link on a page. When users click a link, the code executes a pop-up alert window asks them to confirm that this is the link they wanted to click. This is perfect for server side programs that delete files on a server or modify data in a database. (View the test page.)

Source Code:

<script>
function confirmDelete(delUrl,name_cat) {
if (confirm(“Are you sure you want to delete \nrow number \”” name_cat “\”\nfrom the database”)) {
document.location = delUrl;
}
}
</script>

<!– now the html link –>

<a href=”javascript:confirmDelete(‘yourpage.php?delete=293′,’293’)”>Delete</a>

Adding it to your site:

There are just a few areas you will need to change to customize the code for your use. Number one is the message inside of the javascript event handler (“Are you sure you want to delete \nrow number \”” name_cat “\”\nfrom the database”). Notice I used (\n) for a new line and (\”) for quotes. You can delete them if you like. You can also delete or move around the (” name_cat “) inside the message.

The second thing you will have to modify is the link values (‘yourpage.php?delete=293′,’293’). Change the file name to your serverside program file path and change the id row numbers (‘293’) to the id row number of your database rows.

You may also like...

No Responses

  1. Joey R says:

    I am a newbee. I have a submit button on my asp page that deletes my record from sql database. I am not sure where your code should go and how to make the warning window pop up. Then return to the main page. Can you help me.

  2. iput says:

    this is a question, where we must put this source : <script>
    function confirmDelete(delUrl,name_cat) {
    if (confirm("Are you sure you want to delete \nrow number \"" name_cat "\"\nfrom the database")) {
    document.location = delUrl;
    }
    }
    </script>

    or maybe. like confirmdelete.php, just like that. i beg your pardon, i am not clearly understand.

    thank

    iput

Leave a Reply