Reputation: 395
I am using Javascript to generate html like this
for (var count = 0; count < data.length; count++) {
var provider = data[count].Provider;
var icon_provider = provider.toLowerCase();
html=html+"some code here";
html = html + "<div class=\"icon\"><i class=\"fa fa-" + icon_provider + "\"></i></div><a href=\"#\" class=\"small-box-footer\" onclick=\"myFunction()\">More info <i class=\"fa fa-arrow-circle-right\"></i></a></div></div>";
}
I am calling a function called "myFunction"
when clicked
.
function myFunction() {
$('#myModal').modal('show')
}
all this is in a indexInvoice.js file.
Now i have a index page
which has all the scripts.
<!--javascript for the index page-->
<script type="text/javascript" src="js/IndexInvoice.js"></script>
<!--jQuery for modal window from bootstrap-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').focus()
})
</script>
and the div
where html is generated through javascript(from indexInvoice.js) is this.
<div id="row1" class="row">
<!--Modal window-->
<div class="modal fade" data-target="#myModal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
this is modal window
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div><!-- /.row -->
The div has a std modal window code from bootstrap.
Now the Issue is when I click
the that element, I am not able to get the modal window. Although when a put a alert
in myFunction
it shows the alert
.
Upvotes: 1
Views: 158
Reputation: 8322
it should be $('#myModal').modal("show");
check the double quotes
Upvotes: 1