Javascript – How to check if a checkbox is checked or unchecked with javascript


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) {
    else if (!document.forms[0].help_text.checked) {

<div id="tooltiponoff">
<form action="">
@Html.CheckBox("help_text", true, new { id = "help_text", onclick = "EnableDisableToolTip()" })Hjælpetekst

It only alerts Unchecked when i click it

Thanks in advance

Best Solution

It seems to work for me - please see this fiddle. Note that the event listener is added by Javascript, instead of using the inline onclick syntax.