Jquery and Bootstrap modalbox code is in same page lets 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: DIV is getting ajax response html and elements are drawn dynamically. And after the elements are drawn in this case checkbox . On saveChange button click on modal I want to get checkbox value.
$("#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 able to access elements from other DIV outside modal
How check modal is open or not in jQuery? You can simply use the modal('show') method to show or open the modal window in Bootstrap using jQuery. Other related Bootstrap's modal methods are modal('hide') and modal('toggle') .
Data can be passed to the modal body from the HTML document which gets displayed when the modal pops up. To pass data into the modal body jquery methods are used. jQuery is similar to JavaScript, however jQuery methods are simple and easier to implement. jQuery reduces the lines of code.
JQuery Modal is an overlay dialog box or in other words, a popup window that is made to display on the top or 'overlayed' on the current page. It is a pop up modal box that is converted into the viewport deliberately for the user to interact with before he can return to the actual site.
on('show. bs. modal', function (e) { console. log('modal opened'); // Your code goes here });
Attach your event to a container instead to the element directly. Also use on('click', ...
instead of click
directly.
$("#tileModal").on('click', '#saveChange', function () {
var midVal = $('#test1').val();
console.log(midVal);
});
My solution to check if the check box was checked or not was simple. I just created class and was able to easily check if checkbox was checked or not in the bootstrap modal
$('.className').is(':checked'); // works $('#elementId').is(':checked'); // gives false always
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With