Your selector for chkImm
is wrong, use #chkImm
For jQuery 1.6+ :
.attr() is deprecated for properties; use the new .prop() function instead as:
$('#myCheckbox').prop('checked', true); // Checks it
$('#myCheckbox').prop('checked', false); // Unchecks it
For jQuery < 1.6:
To check/uncheck a checkbox, use the attribute checked
and alter that. With jQuery you can do:
$('#myCheckbox').attr('checked', true); // Checks it
$('#myCheckbox').attr('checked', false); // Unchecks it
Reference: https://stackoverflow.com/a/17420580/1715121
$('#chkImm').on('change', function() {
if ($(this).is(':checked')) {
$("#myModal").modal({
backdrop: 'static',
eyboard: false
});
}
});
$('#btnModalCancel').click(function() {
$('#chkImm').attr('checked', false);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<form class="form">
<input id="chkImm" type="checkbox"><label>Turn on</label>
</form>
</div>
<div id="myModal" class="modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Предупреждение, вы уверены!</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Блаблабла</p>
</div>
<div class="modal-footer">
<button type="button" id="btnModalAgree" class="btn btn-warning">Я уверен, и хочу продолжить</button>
<button type="button" id="btnModalCancel" class="btn btn-secondary" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>