Well, I have a delete button that has a href addressed to the php delete file. I would like to display a confirmation message before sending the record to the delete page. I used the confirm () method of java script to bar the href of the link and it worked, but I wanted to display a more custom message and for that, I used a javaScript framework called sweetAlert. Through the onclick function in the link, I call the function of the confirmation message, and in the function, if the option is true, I send through window.location.href to the php delete file. My question: Since there are records coming through a while loop directly from the database, how can I send the record ID for the function responsible for the confirmation message? Since the record identifier code (pk) is in a php variable and the function is js. Here is the code:
//código do link
<a onclick="confirma_excluir_cliente('');" href="exclui_cliente.php?codigo=<?=$linha['codigo']?>" class="btn btn-danger"><i class="fa fa-trash"></i></a>
//funcao da mensagem
var confirma_excluir_cliente = function(){
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false,
},
function(isConfirm){
if (isConfirm) {
window.location.href="exclui_cliente.php"
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
}
Thank you in advance