% Scripts in Acrobat pro fields

Community Beginner ,
Dec 05, 2017

Copy link to clipboard

Copied

Hi Folks, I know nothing about scripts, but am trying to show a % in a field based on a total in 1 field minus a figure in a 2nd field = the % in the 3rd field. Anybody know if this is achievable?

Apologies, I get it now.

Thank you for being patient with me.

I still do not understand coding (or math it seems!) - but this script has worked. I just need to paste it into the other cells on the form and adjust the target cells.

Thank you so much for your help with this - I am most grateful.

TOPICS
Acrobat SDK and JavaScript

Views

194

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

% Scripts in Acrobat pro fields

Community Beginner ,
Dec 05, 2017

Copy link to clipboard

Copied

Hi Folks, I know nothing about scripts, but am trying to show a % in a field based on a total in 1 field minus a figure in a 2nd field = the % in the 3rd field. Anybody know if this is achievable?

Apologies, I get it now.

Thank you for being patient with me.

I still do not understand coding (or math it seems!) - but this script has worked. I just need to paste it into the other cells on the form and adjust the target cells.

Thank you so much for your help with this - I am most grateful.

TOPICS
Acrobat SDK and JavaScript

Views

195

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
Dec 05, 2017 0
Community Beginner ,
Dec 05, 2017

Copy link to clipboard

Copied

Example:

My clients is sending 1000 newly hatched chicks via an airline

14 of these chicks die in transit

So I need the 3rd box to show 1.4%

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...
Dec 05, 2017 0
Adobe Community Professional ,
Dec 05, 2017

Copy link to clipboard

Copied

This is a standard formatting option.  Look on the Format tab of the field properties

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...
Dec 05, 2017 0
Community Beginner ,
Dec 06, 2017

Copy link to clipboard

Copied

Thank you Thom,

I have formatted the cell Percentage, what I am after is a script that will show (C) as a % of box (B) based on the total in box (A).

Screen Shot 2017-12-06 at 10.42.57.png

I actually need box (C) to show 2% in this example rather than 98%

try67

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...
Dec 06, 2017 0
Most Valuable Participant ,
Dec 06, 2017

Copy link to clipboard

Copied

What's your current code/formula?

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...
Dec 06, 2017 0
Community Beginner ,
Dec 06, 2017

Copy link to clipboard

Copied

I do not have one - all I have done is get Acrobat to add up day 1-7 figures and put a total in the bottom box.

Illustration was for guidance only - but reading the forums, I appear to need a script of some sort.

Client would like to know the % of losses based on the total number of chicks sent.

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...
Dec 06, 2017 0
Most Valuable Participant ,
Dec 06, 2017

Copy link to clipboard

Copied

You have to start by figuring how to do this calculation (on paper for instance). Only once you know the math can you convert that to JavaScript.

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...
Dec 06, 2017 1
Most Valuable Participant ,
Dec 06, 2017

Copy link to clipboard

Copied

Then how did you get the result of 98% in the screenshot above?

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...
Dec 06, 2017 0
Community Beginner ,
Dec 06, 2017

Copy link to clipboard

Copied

I experimented by copying some code I found on one of the other forums posts.

It doesn't work correctly, but I could see what was needed:

var a = Number(this.getField("27 32No of Chicks_2").value);

var b = Number(this.getField("27 32No of Chicks_2").value) + Number(this.getField("DAY 17_2").value);

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

else event.value = (a/b);

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...
Dec 06, 2017 0
Most Valuable Participant ,
Dec 06, 2017

Copy link to clipboard

Copied

Change the last line to:

else event.value = 1-(a/b);

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...
Dec 06, 2017 0
Community Beginner ,
Dec 06, 2017

Copy link to clipboard

Copied

Wow - that seems to work(ish)

If I change the top number to 100 and by inputting 2x10 in the cells, the bottom should be 20% but I get this:   Screen Shot 2017-12-06 at 15.46.04.png

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...
Dec 06, 2017 0
Most Valuable Participant ,
Dec 06, 2017

Copy link to clipboard

Copied

You need to divide by the total number, not the total number plus the sum.

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...
Dec 06, 2017 0
Community Beginner ,
Dec 06, 2017

Copy link to clipboard

Copied

Aah ok - how would I do that - as I said, this java stuff might as well be Klingon to me  

I really do appreciate you help.

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...
Dec 06, 2017 0
Most Valuable Participant ,
Dec 06, 2017

Copy link to clipboard

Copied

If I understand it correctly, it should be:

var a = Number(this.getField("DAY 17_2").value);

var b = Number(this.getField("27 32No of Chicks_2").value);

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

else event.value = (a/b);

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...
Dec 06, 2017 0
Community Beginner ,
Dec 06, 2017

Copy link to clipboard

Copied

Ok - that seems to work well with 100 or 1000 chicks, but doesn't seem to work with an uneven number (which it may well be).

Any suggestions?  

Screen Shot 2017-12-06 at 16.17.25.png

Figure should be 5.34% at the bottom?

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...
Dec 06, 2017 0
Most Valuable Participant ,
Dec 06, 2017

Copy link to clipboard

Copied

10 out of 534 is not 5.34%... It's 1.87%.

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...
Dec 06, 2017 0
Community Beginner ,
Dec 06, 2017

Copy link to clipboard

Copied

Apologies, I get it now.

Thank you for being patient with me.

I still do not understand coding (or math it seems!) - but this script has worked. I just need to paste it into the other cells on the form and adjust the target cells.

Thank you so much for your help with this - I am most grateful.

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...
Dec 06, 2017 0