Please tell me where I've gone wrong. My script isn't working correctly.
I need a count of a filled-in (non-null) text field of a repeating subform (subform1). The count will be calculated in a numeric field of a different subform (subform 2).
* I need the count to be automatically updated when another instance of subform1 is added and the text field of subform 1 is filled in.
* If an instance is added, but the text field is not filled-in, it should not be included in the count.
* Also, if an instance is removed, the count of the remaining instances should automatically recalculate.
I am using LCD v.8.05.
I have placed the execCalculate() command in the EXIT event of subform 1's text field (which is part of the repeating subform).
I have placed the following script in the CALCULATE event of subform 2's numeric field.
var aName = xfa.resolveNodes("C1.Registration.Attendee[*]"); // get all instances of text field "Attendee" of repeating subform "Registration". for (i=0; i<aName.length; i++) // loop through all instances. { if ((aName.item(i).rawValue != null) && (aName.item(i).rawValue.length > 0)) // If text field is not null { var nCount = 0; nCount++; // increment count } } nCount; // RawValue of numeric field is total count.
The result is "1" when I fill-in the first instance of the text field, but the count doesn't change when other instnces are filled-in.
Just in general, the calculate event is called each time any form field is modified. It is not called for structural changes on the form. So the execCalculate() fucntion should only be called for structural changes, i.e., place it in the scripts you use for adding and removing instances, not in the exit event of a text field.
Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]
The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]
Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script