The title may seem a bit confusing but what I want is basically this: in the onclick of the button pass to a function A a function B as a parameter.
I have a list of products each with a different code. I have the following button for each product that onclick has the function modalConfirmation () where I pass as parameter the title and message of the modal and the function to be executed that in the case is deleteProduct ():
<a onClick="script: modalConfirmacao('+"'Confirmar'"+','+"'Tem certeza que deseja excluir?'"+',excluirProduto('+produtos.codigo+'));"> <i class=" fa fa-check"></i> Excluir</a>
The problem is that without me confirming the deletion it is already calling the deleteProduct () function. In the last line of the code snippet below you realize that you should only call the function passed via parameter if the ok button is clicked. But before that it already executes the function.
function modalConfirmacao(titulo, mensagem,funcao) {
var htmlModal = '<div class="modal fade" id="modalConfirmacao" tabindex="-1" role="dialog" aria-hidden="true">' +
'<div class="modal-dialog">'+
'<div class="modal-content">'+
'<!-- Modal Header -->'+
'<div class="modal-header">'+
'<h4 class="modal-title" id="myModalLabel">'+
titulo
+'</h4>'+
'<button type="button" class="close" data-dismiss="modal">'+
'×'+
'</button>'+
'</div>'+
'<!-- Modal Body -->'+
'<div class="modal-body">'+
mensagem
+'</div>'+
'<!-- Modal Footer -->'+
'<div class="modal-footer">'+
'<button type="button" id="ok" class="btn btn-primary" data-dismiss="modal">'+
'OK'+
'</button>'+
'<button type="button" id="cancelar" class="btn btn-default" data-dismiss="modal">'+
'Cancelar'+
'</button>'+
'</div>'+
'</div>'+
'</div>' +
'</div>';
$('body').append(htmlModal);
$("#modalConfirmacao").modal();
$("#ok").off("click").on("click",funcao);
}
I think it's because of the parentheses but I need to use them to pass the parameter product.code that is the product to be excluded.
So how can I pass the DeleteProduct () function together with the parameter without executing it?