Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap check if check box is checked or not [duplicate]

I have a bootstrap checkbox the problem is I can't get the value of it when it is checked. The code below is my check box.

<div class="col-md-auto">
   <div class="form-group">
       <div class="form-check">
           <label class="form-check-label">
              <input type="checkbox" class="form-check-input" id="briskbusiness" value="1">
              Brisk Business
              <i class="input-frame"></i>
          </label>
       </div>
   </div>
</div>

Here is my Jquery:

$(document).on('change','#briskbusiness',function() {
    if(this.checked){
       alert();
    }
});

I tried using click and change and still it won't show alert.

Here is the look of my check box.

Image

like image 940
Maricris Avatar asked Oct 22 '25 04:10

Maricris


1 Answers

Your code seems to be working fine. may me issue with importing jQuery library

<script
  src="https://code.jquery.com/jquery-3.5.1.min.js"
  integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
  crossorigin="anonymous"></script>
<div class="col-md-auto">
    <div class="form-group">
        <div class="form-check">
            <label class="form-check-label">
               <input type="checkbox" class="form-check-input" id="briskbusiness" value="1">
               Brisk Business
               <i class="input-frame"></i>
           </label>
        </div>
    </div>
 </div>


 <script>
     $(document).on('change','#briskbusiness',function() {
         a = $("input[type='checkbox']").val();
    if(this.checked){
       alert(a);
    }
});
 </script>

check above code.

like image 193
Abhishek Singh Avatar answered Oct 23 '25 19:10

Abhishek Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!