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

Help with Percentages

witchybrit
Registered: Oct 13 2009
Posts: 12
Answered

OK So I have a form I am creating in Adobe Acrobat 8. I want to simply have 1 field display 4% of another field. Can anyone help me with this? I have been pulling my hair out.

Cheers!

My Product Information:
Acrobat Pro 8.1.6, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
To do this you'll need to use a Calculation Script in the field that displays the 4%.

For example, if the source field is named "SourceField", then enter this script into the Custom "Calcuation" Script area of the destination field.

event.value = this.getField("SourceField").value * 0.04;

You can find form information on performing calculations in the tutorials on this site. Here's one:

http://www.acrobatusers.com/tutorials/2006/form_calculations

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

witchybrit
Registered: Oct 13 2009
Posts: 12
Thomp, you rock!! Thanks!
witchybrit
Registered: Oct 13 2009
Posts: 12
What if I need it to take in the values of like 2 fields and then give the 4% from that total?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
And the answer is...

event.value = (this.getField("SourceField1").value + this.getField("SourceField2").value)* 0.04;

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

witchybrit
Registered: Oct 13 2009
Posts: 12
Again...you rock :) Cheers!
witchybrit
Registered: Oct 13 2009
Posts: 12
OK - Everything has been doing great but now this is happening.

I have 2 fields AMOUNT and OTHER FEES - The 4% box is showing 4% of the sum of AMOUNT and OTHER FEES.

I am using this

event.value = this.getField("AMOUNT").value + this.getField("OTHERFEES").value * 0.04;

However it is simply just showing me the total from AMOUNT and not 4% of the total.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The values of AMOUNT and "OTHERFEES" have to be added before mulitplying by the 4%. The calculation above is missing the parentheses that group the addition. There is also a difference between the names given to "OTHERFEES", i.e. "OTHER FEES" is shown with a space in some places. Just to be sure, the field names have to match exactly. Try this.

event.value = ( this.getField("AMOUNT").value + this.getField("OTHERFEES").value ) * 0.04;

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

witchybrit
Registered: Oct 13 2009
Posts: 12
OK I am starting to get this now and see what is happening lol - OK so my last question for you is this:

It works super fab right now BUT what if I have no OTHERFEES - I am noticing that if that is left at 0 then it will not calculate the 4% on the AMOUNT box alone.

Is that possible?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Have you checked the 'calculation order' that your form is using?

Your fields maybe being calculated in a different order than you think they should be.

You will have to "Forms => Edit in Acrobat" "Forms => Edit Fields => Set Field Calculation Order".

George Kaiser

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Details, details. It's possible that the value in OTHERFEES is being interpreted as a string, in this case the calculation would fail. But there could be a host of other issues as well. We're at the point where I can't really say anything without seeing whats really going on.

Try this. Open the form in Acrobat, Enter a big number in Amount and a 0 in OTHERFEES. Hit Return. What exactly appears in the result field? Now press Command + J, this displays the Console Window. What do you see printed here?

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