i came up from this link Passing data to a bootstrap modal but yet still after hours, I cant find my way to do it on my own. I want to get the id of the button (let say i will do this via jsp) this is the button
<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg" data-id="p_id">Launch demo modal</a>
and here is the modal
<div class="modal fade" 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-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<input type="text" name="p_id" id="p_id" value=""/>
<hr>
</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><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
With this <script>
just above the button
$(document).on("click", "#myModal", function () {
var myBookId = $(this).data('id');
$(".modal-body #p_id").val( myBookId );
});
The ID should be display in the <input type="text" name="p_id" id="p_id" value=""/>
I almost spend my whole night figuring this out.