Reputation: 1381
I have a table that looks like this
Name Occupation Detail
abc student details
i want to set a bootstrap modal link on details column, which not only works as a model but also picks the id of that specific row.
At present i am working with this code
echo "<td><a href='#myModal'?id=".$row['id']."\" data-toggle='modal' data-target='#myModal '>Details</a></td>";
Modal is working properly but i am not able to use id of the row properly with the modal Would appreciate if someone could help me
Upvotes: 0
Views: 4562
Reputation: 7246
http://jsfiddle.net/0u19axax/1/
You can use show.bs.modal
event to extract data from your a
.
$('#myModal').on('show.bs.modal', function(e){
console.log($(e.relatedTarget).attr('data-id'))
})
I moved the id to data-id
because it did not work with the id in href
<a href='#myModal' data-id='.$row['id'].' data-toggle='modal' data-target='#myModal '>Details</a>
Sorry, I don't know PHP so I'm not sure it'll work PHP wise.
Upvotes: 1