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

% Scripts in Acrobat pro fields

Community Beginner ,
Dec 05, 2017 Dec 05, 2017

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?

TOPICS
Acrobat SDK and JavaScript
1.4K
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 Beginner , Dec 06, 2017 Dec 06, 2017

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.

Translate
Community Beginner ,
Dec 05, 2017 Dec 05, 2017

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%

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

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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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

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​

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

What's your current code/formula?

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

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.

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

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.

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

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

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

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);

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

Change the last line to:

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

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

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

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

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

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

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.

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

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);

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

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?

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

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

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

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.

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