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

1
  • 3
    This question is very informative for beginner web developers. :) Commented Oct 22, 2020 at 6:39

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I've been debugging this for an hour now the problem is I did not import the javascript for the onchange event T_T
0
$(document).ready(function (){ $("#briskbusiness").click(function(){ let check_box = $(this); check_val = checkbox.val(); alert(check_val); }); }) 

1 Comment

Please add some explanation to your answer such that others can learn from it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.