Confirm Delete on Button Click in Javascript

confirm delete button work, If the user selects ‘Ok‘ then href redirect to ” url_to_delete “, else if ‘Cancel‘ is clicked nothing happens.

Method 1

Table of Contents

The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button.

 <a href="url_to_delete" onclick="return confirm('Are you sure you want to delete this item?');">Delete</a>

Method 2

create a button with a function name ” ConfirmDelete “.

<input type="button" onclick="ConfirmDelete()">


Here we simply show a confirmation box to delete if the user selects “ok” then returns true otherwise returns false.

function ConfirmDelete()
  var x = confirm("Are you sure you want to delete?");
  if (x)
      return true;
    return false;

I hope, it will help you.