How to Make Checkbox Field Required in Form in HTML

Last Updated on October 14, 2021 by Roshan Parihar

In this tutorial, learn how to make checkbox field required in a form with HTML and jQuery. The short answer is to use the :checked checker and find the length of checkboxes.

The checkboxes are a useful part of a form to provide users multiple choices for selection. You can make it required to get the required data from users. If you do not make the checkbox field required in HTML, your users may skip filling the field and submit the form that will not give you the required data.

Always make a checkbox field required with the method given in this post below. So, let’s find out how to make the checkbox field required in a form in HTML using jQuery.

How to Make Checkbox Field Required in Form in HTML

To make a checkbox field, you need to use a little bit of jQuery to find if one of the checkboxes in the checkbox field is checked or not. The jQuery first gets the length of the checked checkbox if available. If the checkbox is not checked, it gives an alert box that will not allow users to submit the form. See the below example to learn the method.

Test it Live

Output

HTML input type checkbox element make required

The above example contains the checkboxes to give users multiple choices for selection. If you click the button without selecting any checkbox, you will get an alert message to select the checkbox. This will not allow users to submit the form without making any selection.

The required attribute will not help you in making the checkboxes required. You need some jQuery given above to do perform this task. This is a simple method and useful for anyone who is using forms with checkboxes.

You May Also Like to Read

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.