Check/Uncheck - ifChecked not working

13,028

Try:

on page load:

 alert($('input').is(':checked'));

http://jsfiddle.net/9ypwjvt4/18/

else use:

   $(document).ready(function () {
    $('input').iCheck({
        checkboxClass: 'icheckbox_square-orange',
        radioClass: 'iradio_square-orange',
        increaseArea: '20%' // optional
    });

    $('input').on('ifChecked', function(event){
      alert('Checked');
    });

    $('input').on('ifUnchecked', function(event){
      alert('unchecked');
    });
});

jsfiddle: http://jsfiddle.net/9ypwjvt4/17/

Share:
13,028
Nick Kahn
Author by

Nick Kahn

Updated on June 08, 2022

Comments

  • Nick Kahn
    Nick Kahn about 2 years

    UPDATE: I'm using the following plugin

    I'm trying to check if the checkbox is checked when the user refresh the page or reload the page and here is what I have used but I have done the debugging and it never execute the second IF condition

    $('input').on('ifChecked', function (event) {
        if ($("input#CreatePart").is(':checked')) {
            alert('checked');
        }
    });
    
    $('input').on('ifUnchecked', function (event) {
        if ($("input#CreatePart").is(':checked')) {
            alert('un-checked');
        }
    });
    
    <input checked="checked" class="icheck" data-val="true" 
      data-val-required="The Create new Part field is required." 
      id="CreatePart" name="CreatePart" type="checkbox" value="true" 
    />
    <input name="CreatePart" type="hidden" value="false" />