I'm trying to figure out how to call a Javascript function only when a checkbox is NOT checked.
Here is my checkbox:
<input type="checkbox" id="icd" name="icd" value="icd" />
Here is the name of the function:
planhide();
Include onchange option in the input tag and then add an intermediate function that checks and calls planhide() accordingly as follows:
<input type="checkbox" id="icd" name="icd" value="icd" onchange=check()/>
Then define the check() to do check the state and call the function as follows:
function check()
{
if(document.getElementById("icd").checked==false)
planhide();
}
Also instead of onchange you can also use onclick on the submit button option to call the check() function as like follows:
<input type="button" onclick=check()/>
$(document).ready(function () {
$('#icd').change(function () {
if (!this.checked) {
planhide();
}
});
});
just register an onchange handler on your input, check the 'checked' property when the handler is call, and call the method if checked is false.