I tested your first piece of code on a form and it does not work at all.
When form input is important, it should always be verified using a secure server-side script.
Normally you would modify this so that you could submit or not submit the form based on the number of items selected. For example, a text input that only needs to have a value if a checkbox is checked: Using simple logical operators and the functions supplied above you can do all sorts of client-side form validation.
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.
Note Front Page Server Extensions are a set of programs that provide access to special Front Page features, such as database processing, form processing, hit counters, and other built-in Front Page components that require server-side processing.
You can provide custom validation for your forms in two ways: server-side validation and client-side validation.