Skip to main content
Participant
September 26, 2020
Answered

Formatting Question: Java (?) calculations in forms in Adobe Acrobat

  • September 26, 2020
  • 2 replies
  • 1074 views
Hello - thanks for hopefully attempting to answer my question. 
 
I'm trying to set up formatting/auto functions in fields in forms using Adobe Acrobat calculations. What I am wanting to do is have around 4 - 5 fields in a form which all add up. Pretty simple so far (ie go to properties in the form and add etc). 
However I'm wanting the fields that I enter a number into and then the final "calculator field" in the form to be formatted with an automatic "+" or "-" depending on what is entered. 
 
Two examples both using 4 fields that I enter data into in the form and one "calculator field:
 
EXAMPLE 1: 
What I enter: Field 1; "4",  Field 2; "10",  Field 3; "-5",  Field 4; "25", Final "Calculator field"; "34"
What I would like to see in Example 1:  Field 1; "+4",  Field 2; "+10",  Field 3; "-5",  Field 4; "+25", Final "Calculator field"; "+34"
 
EXAMPLE 2
What I enter: Field 1; "10",  Field 2; "-25",  Field 3; "0",  Field 4; "-5", Final "Calculator field"; "-20"
What I would like to see in Example 1:  Field 1; "+10",  Field 2; "-25",  Field 3; "-",  Field 4; "-5"; Final "Calculator field";  "-20"
 
In other words I am seeking that a positive number have a "+" in front of it, a negative number have a "-" in front of it and zero result have a "-"/dash in the field. 
 
My understanding is that the script would need to be entered into the "Custom Calculate script" box in the Properties of the "calculator field". Am I correct? And I understand that that should be in Javascript correct? 
 
If so, what is the script I need to achieve what I am after? 
 
Thanks very much and look forward to hearing back with any ideas anyone would care to share. 
 
Kind regards
 
Chris
This topic has been closed for replies.
Correct answer Nesa Nurani

For 0 add this code also:

if(event.value == 0){event.value = "-";}

2 replies

try67
Community Expert
Community Expert
September 26, 2020

It's JavaScript, not Java. Similar names, very different languages.

C5C28Author
Participant
October 4, 2020

thanks - I didn't know that.

Nesa Nurani
Community Expert
Community Expert
September 26, 2020

Use this code as "Custom Format Script":

if (event.value>0){var cr ="+"}else{var cr=""}AFNumber_Format(0,0,0,0,cr,true)

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 26, 2020

For 0 add this code also:

if(event.value == 0){event.value = "-";}