Click to See Complete Forum and Search --> : Is there a better way to do this?


sonicsix
04-28-2003, 04:57 PM
if (theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[1].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[2].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[3].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[4].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[5].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[6].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[7].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[8].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[9].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[10].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[11].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[12].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[13].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[14].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[15].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[16].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[17].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[18].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[19].selected == true ||
theForm.WITNESS.options[0].selected == true && theForm.WITNESS.options[20].selected == true)
{
error += "Your witness list cannot contain NONE ASSIGNED as well as a name.\n";
}

TIA

pyro
04-28-2003, 05:46 PM
Yes, there is a better way to do that.. ;) Try using a loop, something link this (untested):

if (theForm.WITNESS.options[0].selected == true) {
for (i=1; i<=20; i++) {
if (theForm.WITNESS.options[i].selected == true) {
error += "Your witness list cannot contain NONE ASSIGNED as well as a name.\n";
break;
}
}
}

If that doesn't work... post you HTML....

gil davis
04-28-2003, 05:49 PM
with (document.theForm.WITNESS) {
var cnt = 0;
for (var i=1; i<options.length; i++)
{cnt += options[i].selected ? 1 : 0;}
if ((options[0].selected) && (cnt != 0))
{error += "Your witness list cannot contain NONE ASSIGNED as well as a name.\n";}
}
BTW, "error" is a reserved word. You should pick another name for your variable.

jeffmott
04-28-2003, 06:01 PM
Personally I think Pyro's example was just fine. There is no need for an extra count variable, and his will not redundantly continue through the loop after an error has already been found.

Also, "error" is *not* a reserved word.

gil davis
04-29-2003, 05:37 AM
jeffmott:

As you can see by the times of our posts, pyro and I were working on the problem at the same time. His routine is more efficient than mine.

As to "error", I must have been thinking about onError. My bad.

sonicsix
04-30-2003, 04:38 PM
Thank you very much... I was having a brain cramp on this one.