4

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

Maricris
  • 97
  • 2
  • 8

2 Answers2

5

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.

  • I've been debugging this for an hour now the problem is I did not import the javascript for the onchange event T_T – Maricris Oct 22 '20 at 06:36
0
$(document).ready(function (){
  $("#briskbusiness").click(function(){
    let check_box = $(this);
    check_val = checkbox.val();
    alert(check_val);
  });
})
San
  • 165
  • 1
  • 7