I've got Javascript in a form that adds up all of the numbers in a
column of form fields and displays a total. It works great if every
field has an initial value of 0, but if any of them are null, "NaN"
displays as the total. I tried to add a test for a null value with
the intent to skip adding that field to the accumulator for one
iteration of the "for" loop, but it doesn't work. Can anyone tell me
what I'm doing wrong? Below is the javascript:
function SumFundraisVol( ){
var TotalSumFundRai sVol = 0;
var field = 0;
//Search through the entire array of form elements and
//locate all fields that include the word "Fundrais_v ol"
//in their name. When found, add the value of that form
//element to TotalSumFundRai sVol
for (var i = 0; i<document.form s[0].elements.lengt h; i++) {
field = document.forms[0].elements[i].name.indexOf(' Fundrais_vol');
if (field > -1 && field != null) {
TotalSumFundRai sVol +=
eval(document.f orms[0].elements[i].value);
}
}
document.forms[0].Fndraising_Vol _Total.value =
TotalSumFundRai sVol;
}