Iam working on an app that requires me to calculate the SUM of a some fields.
i have my inputs are:
in1 = df[0][b];
in2 = df[0][c];
in3 = df[0][f];
total
Im pulling the contents as an array, the array could have a gap in between. for instance:
df[1][b] = 123;
df[2][b] = empty or null;
df[3][b] = 456;
df[4][b] = 5567;
the formula is to:
df[0][f] = df[0][c] / df[0][b];
total = sum of df[0][c];
i have tried the following code, it works fine but when i have GAPS (empty or null or NaN), the calculation stops! Any Ideas ?
function updatesum()
{
var kon = 0;
var lenArr = 0;
for (i = 0; i < 1000; i++) {
if(document.forms["sampleform"]["df["+i+"][c]"]) {lenArr++;}
else { break; }
}
var total =0;
for (j = 0; j < lenArr; j++) {
total = total + (document.forms["sampleform"]["df["+j+"][c]"].value-0);
document.forms["sampleform"]["df["+j+"][f]"].value = (document.forms["sampleform"]["df["+j+"][c]"].value-0) / (document.forms["sampleform"]["df["+j+"][b]"].value-0);
}
document.forms["sampleform"]["toplam"].value = total;
document.forms["sampleform"]["kalantutar"].value = total - (document.forms["sampleform"]["odenentutar"].value-0);
}