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

If & Then

Jansenneo
Registered: Mar 2 2010
Posts: 6
Answered

Hi all

I need help with a very simple script. I have 4 boxes A, B, C & D. In box E, I need to it to calculate if sum of boxes A, B and C is less then 7% of box D, then sum of A, B and C; if more then 7% of D, then maximum 7% of D... Please help. Thanks in advance.

My Product Information:
Acrobat Pro 8.1.7, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Read this:

http://www.acrobatusers.com/tutorials/conditional-execution

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

Jansenneo
Registered: Mar 2 2010
Posts: 6
Thanks for your help, Thomp... But it didn't work

var nSubTotal = this.getField("giftInstitution+giftSport+giftCountry").value;
if( nSubTotal < (IncomeSubTotal03*0.07) )
event.value = nSubTotal;
else if( nSubTotal > (IncomeSubTotal03*0.07) )
event.value = IncomeSubTotal03*0.07;

else
event.value = 0;

Is there anything wrong with the scripts? and where should I put it validation or calculations?

Thanks again.
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
getField will only get a single field. Once you have that field's value, you can add it to other values.
So replace the first line of your code with this:

var nSubTotal = this.getField("giftInstitution").value+this.getField("giftSport").value+this.getField("giftCountry").value;

Also, I don't see where you defined IncomeSubTotal03. If it's the value of a field, you will need to use this.getField("IncomeSubTotal03").value

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Jansenneo
Registered: Mar 2 2010
Posts: 6
Hi Try67

Thanks for that... I am totally new at this and slowly getting there... I have change as per your script: -

var nSubTotal = this.getField("giftInstitution").value+this.getField("giftSport").value+
this.getField("giftCountry").value;
if( nSubTotal < (IncomeSubTotal03*0.07) )
event.value = nSubTotal;
else if( nSubTotal > (this.getField("IncomeSubTotal03").value*0.07) )
event.value = this.getField("IncomeSubTotal03").value*0.07;

else
event.value = 0;

I enter these in validate and and in calculation I put through sum in calculation and it's not working... Please help... Thanks.
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2399
You didn't change IncomeSubTotal03 in line 3. Also, you should not place this script in the validation field. Just calculation.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Jansenneo
Registered: Mar 2 2010
Posts: 6
Hi Try67

Just did it and it works. Thanks a lot for your help. Really appreciate it.