Confirmation of form action [duplicate]

0

I have this code to delete a record from the bank. How can I put in my code a form's jquery confirmation (yes no)?

 $('#deleteButton').on('click', function(e){
               // We don't want this to act as a link so cancel the link action
               e.preventDefault();
               doDelete();
           });
    
asked by anonymous 06.12.2018 / 14:37

1 answer

2

You can use confirm(mensagem) of JavaScript, which shows a message (defined by you) for the user and if you click Ok it returns true , if you click Cancelar it returns false :

$('#deleteButton').on('click', function(e){
    // We don't want this to act as a link so cancel the link action
    e.preventDefault();

    if (confirm('Realmente deseja excluir o registro?')) {
        doDelete();
    }
});

The layout of the confirmation window for this function is the default browser, if you want something better elaborated, create a custom bootstrap (modal) you do with the same logic.

    
06.12.2018 / 15:06