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

Calculate form field based on one of two other form fields

redcrew
Registered: Nov 7 2006
Posts: 83

I've done simple calculations on PDF forms in Acrobat in the past, but now I have a form that has totals at the end of the form, based on other form fields.

I could use some help in figuring out how to write the custom code. At least I think I need custom code. I visited the online Acrobat JavaScript reference for forms at:

http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=JavaScript_SectionPage.70.1.php

which didn't provide me with any details. Is there another article, with basic examples I could use for reference?

Here's the calculation script I need help with:

For the total field, the value is based on one of two other fields on the form. Only one of the two fields is used. So the calculation would be based on which field has a value that is not zero. (Both fields have default value of zero.)

Given the two fields are named:

CreditsTotal_1
CreditsTotal_2

Here's what I created, but could use another set of eyes to review it.

var credits_sub1 = this.getField("CreditsTotal_1").value;
var credits_sub2 = this.getField("CreditsTotal_2").value;

if (credits_sub1 > 0)
event.value = credits_sub1
else
event.value = credits_sub2;

My Product Information:
Acrobat Pro 9.3.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Seems fine to me... Is it not working?

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