I am trying to check if a checkbox is checked or not at all times but I’m only getting alerted when the page loads and not at any time when the status has changed.
Here is the code:
<script type="text/javascript">
$(function(){
if ($('#myCheckBox').is(':checked')) {
alert('Yes my checkbox is checked');
} else {
alert('No my checkbox is not checked');
};
});
You have to bind the “change” event of the checkbox:
When the checkbox will be clicked, the handler will be executed.
Further rading: