Jquery and Bootstrap modal code on the same page lets you say index.php
<div class="modal fade" id="tileModal" tabindex="-1" role="dialog" aria- labelledby="mytileModal" 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">Select Tiles</h4> </div> <div class="modal-body"> <div id="result"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary" id="saveChange">Save changes</button> </div> </div> </div> </div>
Note. The DIV receives the html ajax response, and the elements are drawn dynamically. And after the elements are drawn in this case, check the box. On the saveChange button, click on modal, I want to get the value of the checkbox.
$("#saveChange").click(function () { var midVal = $('#test1').val(); console.log(midVal); });
Getting undefined
Not sure why I cannot access modal elements from the same page. However, Im was able to access elements from another DIV outside the modal
source share