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.
To take things a step further you can even explore Ajax Form Validation which lets you supply real-time feedback using server-side scripts triggered by Java Script events.
For an alternative approach to client-side form validation, without Java Script, check out our new article on HTML5 Form Validation which is available now in most modern browsers. The first test in the example is therefore only necessary in order to provide a different error message when the input is blank.
The purpose of a form validation script is to return a boolean value ( to reference form fields, but that can lead to namespace conflicts and why make things more complicated than necessary.
That could be done using Ajax, but would make the CAPTCHA much easier to break.
User-submitted data should also be verified using a secure server-side script.