I'm using JavaScript to calculate conditional totals and I'm getting too many Validate events.
I've simplified the problem so it can be easily reproduced. Assume a form with three lines (subforms LineItem[0], LineItem[1], and LineItem[2]) and each line has two text fields (detail[0], and detail[1]).
In the validate event of each text field I've put a JavaScript call to postTotal( this ); The postTotal function is defined as:
function postTotal( cell )
{
var index = cell.index;
var name = cell.name;
var total = 0.0;
for( var i=0; i< Page1.Data.nodes.length; i++ )
{
if ( Page1.Data.nodes.item(i).name != 'LineItem' ) continue;
var firstNamedNode = Page1.Data.nodes.item(i).nodes.namedItem( name );
if ( isNaN( firstNamedNode.all.item( index ).rawValue ) ) continue;
total = total + parseFloat( firstNamedNode.all.item( index ).rawValue );
}
xfa.host.messageBox( 'total is ' + total );
}
Basically, all this should do is calculate a new total for either detail[0] or detail[1] depending on which column is updated. I realize that you could use FormCalc to do a summation but I'm actually doing conditional summations which cannot be done in FormCalc.
Whenever one of the detail boxes is updated I'm getting six validation events, in other words the event is firing for each one of the text fields even though only one has been updated. Why the extra validation events?
I can work around this by using the exit event in lieu of the validate event, but that's not the point. I'd like to know why validation is reoccurring on all fields even though only one has been changed.
Thanks
Mordechai