While filling an online form, a form is considered complete only after we agree to the termas and conditions. The terms and conditions are given at the bottom of the page with a checkbox to agree on. With the terms and conditions, it is mentioned that the user is solely responsible for the entries entered in the fields. So, if a user agrees to this, he will check the checkbox, else not. This is checkbox validation.
1. required input:
These are the input fields that are essentially required. The simplest change you can make in your input field is as follows:
<p><input type="checkbox" required name="terms"> I accept the <u>Terms and Conditions</u></p>
Browser does not allow the form to be submitted without the checkbox checked. Browsers will recognise and enforce this:
Above code display the following output:
Following output will be seen if checkbox is not checked. You can see screen captures from Firefox and Chrome:
2. Separating form from function
Here output is displayed below and shows if checkbox is not checked. Text alert messages are generated automatically by browser and if checkbox is checked, and the Submit button is clicked, an alert message is displayed (success!) than you will proceed to the next step.
<form onsubmit="return checkForm1(this);">
<p><input type="checkbox" required name="terms"> I accept the <u>Terms and