PDA

View Full Version : Validation Problem


bobbabuoy
02-16-2004, 08:41 PM
I am trying to ensure that a value is entered in two areas (the first two parts of the if statement below) and something other than 0 is entered into the remaining 11 (which are dropdowns). I know the names/ids of the objects are correct. This isn't working.

Basically something has to be entered into one of the first two inputs OR one of the other 11 has to have something other than '0' selected.

Can someone tell me if they see any syntactical issues?

Thanks!


if (document.enter_trng.miles.value == '' &&
document.enter_trng.minutes.value == '' &&
document.enter_trng.Bike.value == 0 &&
document.enter_trng.WgtTrng.value == 0 &&
document.enter_trng.PoolRun.value == 0 &&
document.enter_trng.Swim.value == 0 &&
document.enter_trng.RollerBlade.value == 0 &&
document.enter_trng.RollerSki.value == 0 &&
document.enter_trng.NordicSki.value == 0 &&
document.enter_trng.Calisthenics.value == 0 &&
document.enter_trng.Eliptical.value == 0 &&
document.enter_trng.Yoga.value == 0 &&
document.enter_trng.Misc.value == 0)
{
alert('You have not entered any training.');
return false
}
else
return true;
}


I believe it has something to do with the values of the last 11 items being 0. I tried enclosing them in single quotes but that didn't work either.

Thanks!

Mattys067
02-16-2004, 08:48 PM
first off, you're using the logical AND(&&) operator for everyone when you stated that you only want the first 2 to be correct. It should go like this: After the first 2, instead of the &&, replace it with ||. It should work fine.

bobbabuoy
02-16-2004, 08:51 PM
I mis-stated. One of the inputs has to be non-empty OR one of the dropdowns has got to be non-zero. In other words, there has to be a non-zero number somewhere in order for it to be ok.

Thanks!!!

Mattys067
02-16-2004, 09:04 PM
Sorry, Im not following completely?? Can you explain it a little further?

bobbabuoy
02-16-2004, 09:06 PM
This is part of a function to ensure that the submit button is not pressed unless some fitness training has been entered. If they press the button when the both the first two inputs are empty or the dropdowns are all showing 0 then that means no training was done. I want to trap that and remind them to enter some training so they don't mistakenly think they entered it and then later on find out that it isn't there.