How to Show Delete Confirmation Message using JavaScript

The confirmation message is mandatory before submitting the delete request to the server-side. When you want to verify the user or accept something, it always a good idea to confirm the request before processing. Mostly, the confirmation popup is shown before processing the delete request. You can easily display a confirmation dialog using Window confirm() method in the client-side.

The confirm() method show a dialog box with a message and two buttons (OK and Cancel). This method returns true, if the user clicks OK, otherwise false.

In the following example code snippet, we will show you how to display delete confirmation message with confirm() method using JavaScript.

<button onclick="confirmation()">Delete</button>
function confirmation(){
    var result = confirm("Are you sure to delete?");
    if(result){
        // Delete logic goes here
    }
}

You can also use confirm() method to show confirm box on anchor link (a href tag) click. In the following example code snippet, we will show how to display a confirmation dialog when clicking anchor link using onclick() event.

<a href="action.php" onclick="return confirm('Are you sure to delete?')">Delete</a>

4 Comments

  1. Ali Said...
  2. Nican Diaz Said...
  3. Abdullah Said...
  4. Khan Said...

Leave a reply

keyboard_double_arrow_up