How to show a confirm message before delete?

Shyam K picture Shyam K · Feb 4, 2012 · Viewed 698.3k times · Source

I want to get a confirm message on clicking delete (this maybe a button or an image). If the user selects 'Ok' then delete is done, else if 'Cancel' is clicked nothing happens.

I tried echoing this when the button was clicked, but echoing stuff makes my input boxes and text boxes lose their styles and design.

Answer

Ved picture Ved · Feb 4, 2012

Write this in onclick event of the button:

var result = confirm("Want to delete?");
if (result) {
    //Logic to delete the item
}