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" />
Try:
on page load:
http://jsfiddle.net/9ypwjvt4/18/
else use:
jsfiddle: http://jsfiddle.net/9ypwjvt4/17/
Use on change event instead on using ifChecked or ifUnchecked
Change your condition on ifUnchecked to make sure the checkbox is NOT checked instead of checked.
You were checking to see if the box is checked when the unchecked event is fired which that would never happen.
DEMO:
http://jsfiddle.net/ejLbgt7b/