I have been trying to implement the accepted answer to this question but have not been able to get the modal to display.
The buttons that should trigger the modal are coded like this:
<a class="btn btn-success btn-xs openModal" data-target="#myModal" data-id=1><span class="glyphicon glyphicon-edit"></span> Edit</a>
The script that should be triggered when the button is clicked is:
<script>
alert("id=" + $(this).attr('data-id'));
$('.openModal').click(function () {
var id = $(this).attr('data-id');
$.ajax({url: "testModal.php?id=" + id, cache: false, success: function (result) {
$(".modal-content").html(result);
}});
});
</script>
I added an alert() command so I can tell if the script is executed.
I do not see the alert dialog when I click on any of the buttons that should trigger it. I do see the alert dialog when the page is first loaded for some reason.
I have tried placing the script in the head section of the html file and also at the end of the body section but it is not executed in either case.
The html for the modal is
<div style="margin-top:5%;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content"></div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Edit Venue</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
Can someone please explain why the script is not being executed when a button is clicked?
Thanks, Pete