Hey guys, I’m just working on an assignment for a class.
The instructions require us to do checks on the user input before it is sent to the C++ script.
Well, I’m trying to use a for loop to run through all the user input boxes to use less space and keep it simpler instead of doing everything individually.
I never was very good with loops, so I can’t figure out what I’m doing wrong…
Here’s my code:
[CODE]
{
var val1 = document.getElementById(“cornPounds”).value,
val2 = document.getElementById(“wheatPounds”).value,
val3 = document.getElementById(“barleyPounds”).value,
val4 = document.getElementById(“oatsPounds”).value,
val5 = document.getElementById(“ryePounds”).value,
val = “”;
document.getElementById(“errorPlace”).innerHTML =””;
for (i=0; i<=5; i++)
{
if ((val+=i)=0 || isNaN((val+=i)))
{
document.getElementById(“errorPlace”).innerHTML = “All pound fields must be blank, or greater than 0 and a real number.”;
return false;
}
else
{
return true;
}
}
Maybe something like this can’t be done this way, but to my mind it seems fine.
Anyone know how to fix this to make it work the way I want?
Firebug tells me it’s an invalid assignment on the left-hand side…
Thanks for any help,
Ryan