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
- How to do multiple checkbox validation in Javascript
- Checkbox validation using jQuery
- HTML Form Checkbox with required validation
- Google reCaptcha 2 JavaScript Validation (client side)
- Custom styled checkboxes with Bootstrap
- HTML Form with Checkboxes examples and sample code
- How to create a dropdown with checkbox options with Bootstrap Style
- How to create checkbox in Bootstrap style ?
- How to get checkbox value in form submission