5 Replies Latest reply on Sep 11, 2009 8:40 AM by Big Bad Trevsy

# How can I achieve this  simple calculation?

Hi all,

I rarely dabble in Acrobat scripting and Javascript is totally alien to me, so I would really appreciate any help on this.

I have a PDF form for ordering Christmas cards. I have already created fields so that people can enter a quantity for each card, and a field called "TotalPacks" which SUMs these fields.

I now need to create calculations in two fields:

1. CardCosts

Each pack costs 4, so all I need to do is create a Javascript which automatically gives the answer to this simple equation:

TotalPacks x 4 =

2. PostageCosts

I need a separate field to show the cost of postage, along these lines:

IF TotalPacks = 1-6, PostageCosts = 2.5

IF TotalPacks = 7-12, PostageCosts = 4.5

IF TotalPacks = 13>, PostageCosts = 6.5

How can I automatically achieve this in Javascript? I know a language exists to achieve this, but it's not a language I know, so I'm completely lost. Any help or advice would be very gratefully received. Thanks all.
Best wishes,
BBT

• ###### 1. Re: How can I achieve this  simple calculation?

First Adobe provides 2 applications for creating forms, Acrobat and LiveCycle Designer. Acrobat uses Acrobat JavaScript and LiveCycle Designer has FromCalc and a variation of Acrobat JavaScript. The language syntax and editing environments are different for each application so this information is necessary for providing a more detailed explanation.

• ###### 2. Re: How can I achieve this  simple calculation?

Many thanks for this clarification G.

I'm using Acrobat Pro 9.1.3

Thanks for any advice that you can offer.

Best wishes,

BBT

• ###### 3. Re: How can I achieve this  simple calculation?

I forgot to add that I work for a small charity for people affected by brain tumours, so any voluntary support with this query would be very much appreciated. It will help us sell more of our fundraising products and that, in turn, allows us to provide more support and fund more research into this serious range of diseases.

Thanks in anticipation,

BBT

• ###### 4. Re: How can I achieve this  simple calculation?

When you create a text field, you can set the a number of properties for the field including the format and a calculation. If I were designing the form I would make fields for each item of 'description#', 'packs#', 'cost#', 'totalCost#' and  total fields for 'totalPacks', 'subtotal', 'postage' and 'totalDue'. The '#' should be replaced with the detail line number.

The description will have a format of none, the 'packs' and 'total  Packs' as a 'Number' and 0 decimals. For the 'totalCost', 'subtotal', 'postage' and 'totalDue' use a format of 'Number with 2 decimals, the monetary unit is optional.

For the calculation for the 'totalCost#' one can use either the 'the product of' and select the  'packs#' and 'cost#' for the line entry. The 'subTotal' field will be 'the sum of' and select all of the 'totalCost#' fields. The 'totalPacks' will be 'the sum of' all the 'packs#' fields. The postage will require a custom calculation script:

// compute postage form highest to lowest number of packs
if(this.getField('totalPacks').value > 12) {
event.value = 6.5
}
if(this.getField('totalPacks').value < 13) {
event.value = 4.5
}
if(this.getField('totalPacks').value < 7) {
event.value = 2.5;
}
if(this.getField('totalPacks').value < 1) {
event.value = 0;
}

The 'totalDue' is 'the sum of' 'subTotal', 'postage', and 'totalDue'.

• ###### 5. Re: How can I achieve this  simple calculation?

G - thank you so much.

This worked perfectly.

The time you have taken is hugely appreciated; you really went the extra mile to help me out.

Have a great weekend.

Best wishes,

BBT