0
I have a page called produtos.php
, where I list all products from my database, each product is on a table and each one has its respective button of details,edit and delete, I can pass the id for my excludes button but I can’t catch it on 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 don’t know much about 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.
the Boot from inside the modal does not take the id
– fabricio
I think what’s wrong is that you’re putting the event click on the modal, and I think it’s supposed to be on the button that opens the modal, then as long as the date attributes exist and are in the right elements I see no reason not to. It would help if you put an example of two or three lines of html in that product listing
– Miguel
'<a class="btn btn-Danger btn-Xs" href="delete.php? id=<? php echo $line['id_product']; ? >" data-toggle="modal" data-name="<? php echo $line['name'] ? >" data-id="<? php echo $line['id_product'] ? >" data-target="#delete-modal">Delete</a>' this is my boot
– fabricio