stack stack - 3 months ago 11
HTML Question

How can I create a confirm popup alert before submitting?

I want to ask

Are you sure you want to delete this comment?
as a popup alert when the users clicks on the button. How ca do that?

$('button').on('click', function(){

// show a alert to the user contains "Are you sure you want to delete this comment?"

if ( /* he pressed "yes" */ ) {
var id = $(this).attr('id');
deleteComment(id);
} else {
// nothing happens
}
});

Answer
$('button').on('click', function(){

    answer = confirm("Are you sure?")

    if (answer == true) {
        var id = $(this).attr('id');
        deleteComment(id);
    } else {
        // nothing happens
    }
});