Skip to content Skip to sidebar Skip to footer

How To Uncheck All Checkboxes When I Close A Modal?

I want to pop up a modal on clicking the checkbox. And wants to uncheck it when I close a modal automatically. I tried both attr and prop methods. None of them worked. //uncheck

Solution 1:

Please use this code I hope it's work for you.

Thanks

$(document).ready(function(){
    $("#myModal").on('hide.bs.modal', function(){
         $('.creditCheckbox').prop('checked', false);
  });
});

Solution 2:

I have to make an example like your code, please review once, hope it will help you, it is working for me. Thanks.

<div class="container">
  <input type="checkbox" name="check" class="checkOption"> check 1
  <input type="checkbox" name="check" class="checkOption"> check 2
  <input type="checkbox" name="check" class="checkOption"> check 3
  <input type="checkbox" name="check" class="checkOption"> check 4
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#cbreInvoiceDetailsModal">Open Modal</button>

  <!--Modal html code-->
<div class="modal fade" id="cbreInvoiceDetailsModal" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Full screen view</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span> 
                 </button>
            </div>
            <div class="modal-body">
                <div class="col-md-12 col-xs-12 col-sm-7">
                    <div class="box_layout" id="show-data">
                        <div class="image_layout">

                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button id="closeInvoiceModal" type="button" 
                    class="btn btn-sm btn-success waves-effect pull-right" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

</div>

<script>
  $(document).ready(function(){
    $("#cbreInvoiceDetailsModal").on('hide.bs.modal', function(){
      $('.checkOption').prop('checked', false);
  });

});
</script>

Post a Comment for "How To Uncheck All Checkboxes When I Close A Modal?"