I have a page called produtos.php
, where all products in my database are ready, each product is in a table and each has its details button, edit and delete, I can pass the id for my delete button but I can not get it in modal .
modal
<!-- Modal -->
<div class="modal fade" id="delete-modal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Fechar"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="modalLabel">Excluir Item</h4>
</div>
<div class="modal-body">
Deseja realmente excluir este item? <span class="nome"></span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary delete">Sim</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Não</button>
</div>
</div>
</div>
</div>
I do not understand much of JS
$('.modal').on('click', function () {
var nome = $(this).data('nome');
var id = $(this).data('id');
$('span.nome').text(nome + ' (id = ' + id + ')');
$('.delete').attr('href', 'apagar.php?id=' + id);
$('#delete-modal').modal('show');
});
HTML / php of the button that opens the modal:
<a class="btn btn-danger btn-xs" href="apagar.php?id=<?php echo $linha['id_produto']; ?>" data-toggle="modal" data-nome="<?php echo $linha['nome'] ?>" data-id="<?php echo $linha['id_produto'] ?>" data-target="#delete-modal">Excluir</a>
This is my button.