3

On my Laravel app when I click on checkbox it is not doing anything which is declared in my JQuery script. Checkbox:

<input type="checkbox" id="terms_info" name="terms_info"/>

Script:

$(document).ready(function (){
    alert('home is ready');

    $("#terms_info").on("click",function() {
        alert('home is checked');
    });
});

Also, there are no errors in the console on Firefox dev tools. Thank you for the help!

5
  • When you click the checkbox, can you run var x = $("#terms_info") in the console or step through and look at the everything and see if it shows you checked it? Commented Aug 28, 2018 at 14:19
  • its not replicable Commented Aug 28, 2018 at 14:20
  • Possible duplicate of jQuery checkbox checked state changed event Commented Aug 28, 2018 at 14:20
  • @Jamesking56 this topic didn't help Commented Aug 28, 2018 at 14:22
  • move it outside document ready. are you creating it dynamically? Commented Aug 28, 2018 at 14:34

3 Answers 3

2

Use change event with event delagation on() instead :

$(document).ready(function() {
  $("body").on("change", "#terms_info", function() {
     if( $(this).is(':checked') ){
        alert('home is checked');
     }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" id="terms_info" name="terms_info" />

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

Comments

2

Try the following:

<script type="text/javascript">
    $(document).ready(function (){
        alert('home is ready');

        $(document).on("click", "#terms_info",function() {
            alert('home is checked');
        });
    });

</script>

and you tell me if it works...

Comments

1

try this

$("#terms_info").click(function() {
            alert('home is checked');
        });
    });

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.