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!

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
Sz3jdii
  • 507
  • 8
  • 23

3 Answers3

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" />
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
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...

1

try this

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