I'm using twitter bootstrap's modal.
I have a table that maps mac addresses to vendor names. The code looks something like this
<tbody>
<?php foreach ($rowarr as $k => $v) { ?>
<tr>
<td><?php echo $k ?></td>
<td>
<div class="divBox">
<a data-toggle="modal" href="#myModal"><?php echo $v; ?></a>
</div>
</td>
</tr>
<?php } ?>
</tbody>
I would like to click on the vendor name (like Cisco, HP) and launch a modal dialog box with more details about the vendor. The details in this modal box would come from a database. I want to use PHP to query the database, but for querying I need to know the name of the link/vendor that was clicked. How can I do so ?
My JS for launching the modal looks like this atm
<script type="text/javascript">
$('#myModal').modal('hide');
</script>
First thing you can do is set the data-vendor in the link by doing:
<a data-toggle="modal" data-vendor="<?= $v ?>" href="#myModal"><?php echo $v; ?></a>
Or you could get the vendor by:
vendor = $("#myModal").html();
Then wire up your click event for the link by doing:
<script type="text/javascript">
$('#myModal').click(function(){
$(this).modal('hide');
var vendor = $(this).data('vendor');
//DO SOME AJAX CALL OR REFRESH THE PAGE USING "vendor"
});
</script>
I also noticed that you are trying to select using by the id $('#myModal'), but there isn't an "id" attribute. You would probably want a class called "myModal" on the "a" tag and then select by using:
$('.myModal').click(function(){ ... });