Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Sep 26, 2020 Sep 26, 2020
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
TOPICS
Acrobat SDK and JavaScript
995
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 26, 2020 Sep 26, 2020

For 0 add this code also:

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

Translate
Community Expert ,
Sep 26, 2020 Sep 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2020 Sep 26, 2020

For 0 add this code also:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 03, 2020 Oct 03, 2020

Great thanks very much for your help Nesa. Really appricate you taking the time to respond.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2020 Sep 26, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 03, 2020 Oct 03, 2020
LATEST

thanks - I didn't know that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines