HTML.form.guide

javascript validation

Checkbox checked validation using JavaScript

You can check whether a checkbox is checked or not using checkbox_elemnt.checked attribute. Here is an example: See the Pen single checkbox validation by Prasanth (@prasanthmj) on CodePen. 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; } }

Continue Reading →

How to do multiple checkbox validation in Javascript

Checkboxes can be used as a single checkbox (like an on-ff switch) or as a group of checkboxes where the user can select one or more options. How do we do validations when you have multiple checkboxes? Here are some samples. At least one checkbox should be checked (Required validation) See the Pen Multiple checkbox validation by Prasanth (@prasanthmj) on CodePen. In the validation code, we extract the FormData object from the form element.

Continue Reading →