Highlighted

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

Community Beginner ,
Sep 26, 2020

Copy link to clipboard

Copied

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

For 0 add this code also:

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

TOPICS
Acrobat SDK and JavaScript, Create PDFs, Edit and convert PDFs, How to, PDF forms

Views

110

Likes

Translate

Translate

Report

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

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

Community Beginner ,
Sep 26, 2020

Copy link to clipboard

Copied

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

For 0 add this code also:

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

TOPICS
Acrobat SDK and JavaScript, Create PDFs, Edit and convert PDFs, How to, PDF forms

Views

111

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 26, 2020 0
Engaged ,
Sep 26, 2020

Copy link to clipboard

Copied

Use this code as "Custom Format Script":

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 26, 2020 1
Engaged ,
Sep 26, 2020

Copy link to clipboard

Copied

For 0 add this code also:

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 26, 2020 0
Community Beginner ,
Oct 03, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 03, 2020 0
Most Valuable Participant ,
Sep 26, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 26, 2020 1
C5C28 LATEST
Community Beginner ,
Oct 03, 2020

Copy link to clipboard

Copied

thanks - I didn't know that.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 03, 2020 0