These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

need two arrays to tally qtys for calculating a price

klwalsh611
Registered: Sep 10 2009
Posts: 28
Answered

I have an order form that has size columns (8 in total) that need to be tallied by size range (cols 1-4 are small sizes at one price & cols 5-8 are lg sizes at a diff price), the totals then each need to be multiplied by their respective unit prices and the final total for the row is the sum of the sm total and the lg total. The template for the size fields is Size1.Row1, Size2.Row1, etc. The prices are smPrice and lgPrice. Each row is numbered down the form in sequence .Row1, .Row2, .Row3, etc.
 
The customer can choose 3 Smalls, 2 Larges, 4 4XLs, 5 - Lg Talls, etc. of a particular product and the total field for that row needs to reflect ((3 + 2) * smPrice) + ((4 + 5) * lgPrice)).
 
I'm guessing I would need to use an array but I'm not sure how to set that up and to take into account if a size field is blank. I'm using Acrobat 9 Pro Ext on Windows. Thanks in advance!
 

My Product Information:
Acrobat Pro Extended 9.4, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
What kind of form do you have? LiveCycle or AcroForm?

Please explain more about your form. What are the values entered into the column fields?

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

klwalsh611
Registered: Sep 10 2009
Posts: 28
It is an Acroform. The values in the size fields are formatted to be numbers (no decimals places). I created a doc-level script that works. If there's a better way of addressing this issue, I'm open to suggestions.

////////////////
// DoTotalCalcSizesBase()
//
// Function for calc the )total qty of smalls * smprice) as one value
// and )total qty of lrgs * upprice) as a second value. Then it totals
// those two values as the final total for the Row.

function DoTotalCalcSizesBase()
{
var cRowName = event.target.name.split(".").pop();
var cSzFld1 = "Size1." + cRowName;
var cSzFld2 = "Size2." + cRowName;
var cSzFld3 = "Size3." + cRowName;
var cSzFld4 = "Size4." + cRowName;
var cSmPrice = "smPrice." + cRowName;
var cSzFld5 = "Size5." + cRowName;
var cSzFld6 = "Size6." + cRowName;
var cUpPrice = "upPrice." + cRowName;

var qtySm = "";
var qtyUp = "";
var qty1Sm = this.getField(cSzFld1).value;
var qty2Sm = this.getField(cSzFld2).value;
var qty3Sm = this.getField(cSzFld3).value;
var qty4Sm = this.getField(cSzFld4).value;
var qty5Up = this.getField(cSzFld5).value;
var qty6Up = this.getField(cSzFld6).value;
var priceSm = this.getField(cSmPrice).value;
var priceUp = this.getField(cUpPrice).value;

{
qtySm = (qty1Sm * 1) + (qty2Sm * 1) + (qty3Sm * 1) + (qty4Sm * 1);
qtyUp = (qty5Up * 1) + (qty6Up * 1);
}
if((qtySm == "" || qtySm == "0") && (qtyUp == "" || qtyUp == "0"))
event.value = "";
else
event.value = (qtySm * priceSm) + (qtyUp * priceUp);
}


thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
You've got the right idea. The only improvement would be to put it in a loop to make it more compact.
When creating tables that will be used in calculations, field names are everything. You can make the coding much easier or much more difficult just by the names you choose. You haven't done bad at all.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script