This is done using HTML5 form validation techniques and CSS, but it only validates the input format (pattern) and not the actual values.That could be done using Ajax, but would make the CAPTCHA much easier to break.In this tutorial you will learn how to validate an HTML form using Java Script.
The illustration below shows this relationship: Note that the 'I' in selected Index needs to be capitalised - Java Script functions and variables are always case-sensitive. Read more about the humble checkbox in our HTML5 Checkbox Validation article.
Radio buttons are implemented as if they were an array of checkboxes.
The problem is that, to have the data submitted in a 'nice' format to the server, the function returns an array containing all the selected checkbox values. Again, we can make the code a lot simpler in supporting browsers: suffix tells a server side script such as PHP to accept multiple values with that name into an array.
Normally you would modify this so that you could submit or not submit the form based on the number of items selected. Note that in this section we've been using the new ES6 syntax which may not be available in all browsers.
It explains some of the code examples above as well as introducing more advanced concepts: We would be remiss in not pointing out that your Java Script and HTML code should be kept separated as far as possible. I've coded a working form, all checks are great but for some reason the hardest part is trying to stop form submission before validation.