Hi all - I’m attempting to sum/add up values within 4 different form fields on the fly, but keep getting a result of NaN…not sure what I’m doing wrong…here’s my code:
function calculate(totalElement) {
for (var i=1,app_pend_end=0;i<5;i++)
app_pend_end += what.elements['textField' + i].value - 0;
totalElement.app_pend_end.value = app_pend_end;
if (totalElement)
{
var calculation = "";
var overall = "";
var fields = new Array();
var userInputs = myform.elements;
for (var f = 0; f < userInputs.length; f++)
{
if (userInputs[f].className=='special_value')
{
if (userInputs[f].value)
{
fields[f] = userInputs[f].value;
}
else
{
fields[f] = 0;
}
}
}
for (var i=0; i<fields.length; i++)
{
calculation += fields[i];
if (i!=fields.length-1)
{
calculation += '+';
}
}
document.writeln(calculation);
if (calculation!='')
{
overall = eval(calculation).toFixed(2);
}
if (overall!='')
{
totalElement.app_pend_end.value = overall;
}
}
}