Skip to main content
Participant
July 22, 2016
Answered

Can you help me to insert a JAVA script into an Adobe PDF form I have created.

  • July 22, 2016
  • 4 replies
  • 1524 views

I have never programmed in Java and need a Java script to insert into a calculation field in an Adobe PDF form I am creating using Adobe Acrobat Pro DC.  This form will be one that can be filled out on the PC or printed out and filled in manually.  The calculated field will display an unwanted zero when printed out and I want it to be blank.  Another field will be a calculated percent and displays an error when there is no divisor; similar problem, I want it to be blank and have the person filing out the form manually to calculate the field and write it in.  I don't have time to learn

The Excel formula would be:  If(Cell_1A="","",Cell_1A+Cell_1B)

What would the JAVA script be in a "Simplified Field Notation" or "Custom Calculation Script" dialog box?

This topic has been closed for replies.
Correct answer try67

Both of these things require a custom calculation. For the division script you can use something like this:

var a = Number(this.getField("Field A").value);

var b = Number(this.getField("Field B").value);

if (b==0) event.value = "";

else event.value = a/b;

For the conditional script you can use this:

var a = this.getField("Cell_1A").valueAsString;

var b = this.getField("Cell_1B").valueAsString;

if (a=="") event.value = "";

else event.value = Number(a)+Number(b);

4 replies

Legend
July 23, 2016

You should note that this is JavaScript (one word, no space, capital S). It is not Java or Java Script. These would be different things. This may not seem important, but if you are searching the web for advice it's very important not to get the wrong stuff, which will be similar enough to trick you, but won't work.

Denny1775Author
Participant
July 26, 2016

I do appreciate the people who correct my misstatements.  In the future I'll use JavaScript correctly.  Thank you.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 23, 2016

Both of these things require a custom calculation. For the division script you can use something like this:

var a = Number(this.getField("Field A").value);

var b = Number(this.getField("Field B").value);

if (b==0) event.value = "";

else event.value = a/b;

For the conditional script you can use this:

var a = this.getField("Cell_1A").valueAsString;

var b = this.getField("Cell_1B").valueAsString;

if (a=="") event.value = "";

else event.value = Number(a)+Number(b);

Denny1775Author
Participant
July 26, 2016

Thank you for the solution.  It solved my problem.