Home
 
The page you are viewing is part of our 160,000 page PDF discussion forum archive spanning 1999-2011.
Go to the new Planet PDF forum to join the PDF community.
 

Search
 Advanced   
Sign up for a WebBoard account Archive Forum Home


PLATINUM
SPONSOR

GOLD
SPONSORS



Topic  
Go to previous topicPrev TopicGo to next topicNext Topic
Author Message
ConeSnail
ConeSnail

Total Messages 4

Subject:Applying same script to many fields.

Hello,

I've got a pdf that is calculating a large amount of fields. I'm wanting to use the same javascript function for each total column.

Beginning Mileage | Ending Mileage | Reimbursable
---------------------------------------------------
Odometer.1 | Odometer.2 | Total.1
---------------------------------------------------
Odometer.3 | Odometer.4 | Total.2

I suppose I could just create a function something like this:

function reimbursableMileage(ending, beginning)
{
var tempEnd = this.getField("Odometer." + ending).value;

var tempBegin = this.getField("Odometer." + beginning).value;

var Total = tempEnd - tempBegin;

event.value = Total;

}

I'm just wanting to make sure this is the faster way of applying this script to hundreds of Reimbursable Mile Fields.

Thanks for any help/advice!


Posted: 22 Jan 2010 11:13 AM
Originally Posted: 22 Jan 2010 11:11 AM
Left Button SpacerView user's profile profileRight Button Spacer
 
 
jkitzy
jkitzy

Total Messages 94

Subject:Applying same script to many fields.

This will be easier if you change the fields to something like this:

Beginning Mileage | Ending Mileage | Reimbursable
---------------------------------------------------
Start.0 | End.0 | Total.0
---------------------------------------------------
Start.1 | End.1 | Total.1


This is important because every item in the collection has the same child identifiers. Then, you can put a calculation event in one of the Total fields:

///////////////////
var a = this.getField("Total");
var b = a.getArray();
var c; var d; var e;
for(var z = 0;z c = this.getField("Start." + z).value*1;
d = this.getField("End." + z).value*1;
if(d!=0){this.getField("Total." + z).value = d-c}}
///////////////////

This will cycle through every set and perform the calculation.

If you need a grand total field, then make these additions and put the script in the GrandTotal field:

///////////////////
var a = this.getField("Total");
var b = a.getArray();
var c; var d; var e; ,var f = 0;
for(var z = 0;z c = this.getField("Start." + z).value*1;
d = this.getField("End." + z).value*1;
if(d!=0){this.getField("Total." + z).value = d-c}
f=f+(d-c);}
event.value = f
///////////////////

Cheers.


---jak


Posted: 23 Jan 2010 02:52 AM
Left Button SpacerView user's profile profileRight Button Spacer
 
 
gkaiseril
gkaiseril

Total Messages 3000

Subject:Applying same script to many fields.

Using some more advance JavaScripting, on can reference an array of fields and then create an array of field objects and use one or all of the arrays to process the form. One does need to carefully name their fields. Having field names 'start.#', 'end.#', and 'total.#' and 'grandTotal', one could use the following script as the custom calculation script for the 'grandTotal' field:

function Difference (fEnd, fStart) {
return fEnd - fStart;
}


// obtain the total field highest level
var oTotal = this.getField('total');
// convert oTotal oject to an array of member fields
var aTotal = oTotal.getArray();
// make array for start and end
var aStart = this.getField('start').getArray();
var aEnd = this.getField('end').getArray();
var fGrandTotal = 0; // variable for Grand Total
var fTotal = 0; // variable for difference
// use elements of aToal array to control computation of each row
for( i = 0; i < aTotal.length; i++){
fTotal = 0;
// compute total for row i if end is not zero
if(aEnd[i].value !=0) {
fTotal = Difference(aEnd[i].value, aStart[i].value);
}
// update total field
aTotal[i].value = fTotal;
// add result to grand total
fGrandTotal += fTotal;
}
// update field value for grand total
event.value = fGrandTotal;



DocumentSumArrayFields.pdf
Summing an array of fields

Posted: 23 Jan 2010 06:20 AM
Left Button SpacerView user's profile profileRight Button Spacer
 
 
ConeSnail
ConeSnail

Total Messages 4

Subject:Applying same script to many fields.

Thanks for the good advice on this everyone. I'm implementing something similar to what gkaiseril posted in his example.

My problem now is some sort of indexing problem that occurs on the next to last field on the first page. Anything after that gets thrown off.

beg.8 end.8 total.8 <----- calculation works
beg.9 end.9 total.9 <----- total shows @ total.11
beg.10 end.10 total.10 <----- total shows @ total.12
--------------------------------------------------

beg.11 end.11 total.11



I'm guessing this is a problem with the page update but so far I haven't been able to find anything about it in the SDK.


Posted: 07 Feb 2010 02:47 PM
Left Button SpacerView user's profile profileRight Button Spacer
 
 
   
Go to previous topicPrev TopicGo to next topicNext Topic

go




Top | News | Developer | Find PDF Tools | Sponsorship | Tips | Home



Debenu's Planet PDF - a comprehensive site exclusively focused on Adobe Acrobat/PDF users and uses. Debenu's Planet PDF - Resources for Adobe Acrobat and PDF users

Please post PDF-related questions to our Planet PDF Forum forums.planetpdf.com. To send comments about this site please visit our contact page.
Planet PDF, Planet PDF Forum, PDF SDK - Debenu Quick PDF Library and Debenu are all copyright
© 2011 Debenu Pty Ltd.. All Rights Reserved. Privacy policy.