Julian4145
Programmer
Can anyone tell me why this code loops through 16 times instead of 8?
var TotalAmount = 0;
var tmpAmount;
for (i = 0; i <= 8; i++){
tmpAmount = parseFloat(form.elements('txtAmount' + i);
if (tmpAmount != 'NaN'){
TotalAmount = TotalAmount + tmpAmount;
alert('TotalAmount');
}
}
I'm trying to test to see if there is a number in a field (txtAmount + i) thats in another loop that runs 8 times. If there is a number, I want to add it to the total. In the testing I was doing there is 400 in txtAmount1 and 50 in txtAmount2 and the other 6 are blank. Eventually, what I am trying to do is to check to see if the total of the txtAmount fields is < 500 and if so to return false. When the code runs, I get an alert box that reads 400 followed by 450, then 6 boxes that read NaN. The alert boxes then repeat themselves a second time.
var TotalAmount = 0;
var tmpAmount;
for (i = 0; i <= 8; i++){
tmpAmount = parseFloat(form.elements('txtAmount' + i);
if (tmpAmount != 'NaN'){
TotalAmount = TotalAmount + tmpAmount;
alert('TotalAmount');
}
}
I'm trying to test to see if there is a number in a field (txtAmount + i) thats in another loop that runs 8 times. If there is a number, I want to add it to the total. In the testing I was doing there is 400 in txtAmount1 and 50 in txtAmount2 and the other 6 are blank. Eventually, what I am trying to do is to check to see if the total of the txtAmount fields is < 500 and if so to return false. When the code runs, I get an alert box that reads 400 followed by 450, then 6 boxes that read NaN. The alert boxes then repeat themselves a second time.