I am trying to check weather a checkbox is checked or unchecked. This is my code:
<script type="text/javascript">
function EnableDisableToolTip() {
if (document.forms[0].help_text.checked) {
alert("Checked");
}
else if (!document.forms[0].help_text.checked) {
alert("Unchecked");
}
}
</script>
<div id="tooltiponoff">
<form action="">
@Html.CheckBox("help_text", true, new { id = "help_text", onclick = "EnableDisableToolTip()" })Hjælpetekst
</form>
</div>
It only alerts Unchecked when i click it
Thanks in advance
It seems to work for me – please see this fiddle. Note that the event listener is added by Javascript, instead of using the inline
onclicksyntax.