form validation assistance (Javascript)

by "Michael Gerholdt" <gerholdt(at)fredonia.edu>

 Date:  Tue, 16 Apr 2002 10:52:47 -0400
 To:  <hwg-techniques(at)hwg.org>
  todo: View Thread, Original
Hi,

We have a form with various elements but most are radio buttons with exactly
the same number of buttons and values - 22 of them.

I got validation to work for them with 22 if-blocks but want to reduce this
to one.

We're using form-level validation with the onSubmit event.

Here's the block I've been working with. If I take out the part that does
the actual validation, the for loop works fine as indicated by the alert.
But apparently I'm missing something on how to pass the value into the if
statement.

btw, we named the radio buttons o1 through o22. (Javascript doesn't like
elements named with numbers alone? This is a nice workaround.)

Appreciate any help!

Thanks,
Mike

for (i=1;i<=22;i++) {
var NUM = i;
NUM = 'o' + NUM;
alert(NUM);
if (!(Evaluation.NUM[0].checked || Evaluation.NUM[1].checked ||
Evaluation.NUM[2].checked || Evaluation.NUM[3].checked ||
Evaluation.NUM[4].checked)) {
alert('Check something, will ya?.');
event.returnValue=false;
document.Evaluation.NUM[0].focus();
return false;
}
}

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA