I have a bootstrap modal l need to activate when l click on a button. For now when the page is rendered and l click on edit button, something pops up like a shadow but the modal with the data is not displayed. I want to use the onclick function, showModal() to activate the bootstrap modal. Any help will be greatly appreciated.Thanks
Here is my code:
$(document).ready(function () {
getAllBooks();
function getAllBooks() {
$.ajax({
type: "GET",
url: "/employees",
success: function (result) {
$.each(result, function (i, customer) {
var customerRow = '<tr>' +
'</td><td><button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" onclick="showModal()" id="5">Edit</button></td>' +
'<div class="modal fade" id="myModal" role="dialog">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal">×</button>' +
'<h4 class="modal-title">Modal Header</h4>' +
'</div>' +
'<div class="modal-body">' +
'<p>Some text in the modal.</p>' +
'</div>' +
'<div class="modal-footer">' +
'<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
'</tr>';
$('#customerTable tbody').append(customerRow);
});
$("#customerTable tbody tr:odd").addClass("info");
},
error: function (e) {
alert("ERROR: ", e);
console.log("ERROR: ", e);
}
})
}
//function to activate bootstrap modal
showModal = function () {
//var buttonId = $('#5').attr('id');
//jQuery.noConflict();
console.log("Hello World!");
$('#5').modal().show();
}
})
<html>
<head>
<title></title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="/js/data.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<table id="customerTable" class="table table-bordered table-hover table-responsive">
<thead>
<tr>
<th>Delete</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>