HTML.form.guide

Checkbox checked validation using JavaScript

checkbox validations javascript validation required validation

You can check whether a checkbox is checked or not using checkbox_elemnt.checked attribute.

Here is an example:

Here is the JavaScript code for easy reference:

function validateForm(form)
{
    console.log("checkbox checked is ", form.agree.checked);
    if(!form.agree.checked)
    {
        document.getElementById('agree_chk_error').style.visibility='visible';
        return false;
    }
    else
    {
        document.getElementById('agree_chk_error').style.visibility='hidden';
        return true;
    }
}

See Also