Checkboxes enforcing a minimum of choices

travisowens

Centurion
Joined
Feb 11, 2004
Messages
108
Location
Rochester, NY
IN a dynamically (via SQL) generated survey I need to enforce a minimum on some checkbox questions. So let's say I have 10 colors and you need to "pick at least 2". Let's assume I have 3 of these questions in my survey.

Ideally, I would like the submit button onclick fire off an alert to tell the user that questions 1, 2, 3 need addressing if they don't have the minimum. I already have a CSS class that toggles to give a visual cue that the question isn't valid, but now I need to actually enforce it. (PS: server side isn't important now)

The only way I can think of doing this is to create a 3x4 array that contains (question#, checkbox name, number of checkboxes, min) .... which would look like (1, 'chkColor_', 10, 2). The function would take each row of the array, loop thourgh all the IDs (via 'chkColor' + for 0 to 9) and if the min isn't met, fire an alert that says "question "+ question + " requires at least "+ min +" choices."

Is there a more efficient way to do this then sending a 3x4 array?
 
Last edited:
Back
Top