Everah wrote:And why in the world would you rely on Javascript to handle something the server should be checking for anyway?
It seems to me it would be reasonable to do that validation in Javascript before submission, though, as an onClick event of the Submit button, so that it would only actually submit a valid request.
As Everah said, you just need to convert the logic you expressed into code. If you will always have the same configuration and rules, you could do it with a series of If statements. I think I would assign a value of 1 (numeric one) to a checked box, so it would be easy to do something like:
Code: Select all
if ((getElementById('chkbx1') + getElementById('chkbx2') + getElementById('chkbx3') == 1)
AND (getElementById('chkbx4') + getElementById('chkbx5') + getElementById('chkbx6') == 1)
AND (getElementById('chkbx5') + getElementById('chkbx6') + getElementById('chkbx7') == 1)
...
AND (getElementById('chkbx22') + getElementById('chkbx23') + getElementById('chkbx24') == 2) {
document.myFormName.submit()
} else {
// give user an alert to correct their entry
}
I haven't thought that through very carefully, but something like that.