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.
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.
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%
Copy link to clipboard
Copied
This is a standard formatting option. Look on the Format tab of the field properties
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).
I actually need box (C) to show 2% in this example rather than 98%
Copy link to clipboard
Copied
What's your current code/formula?
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.
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.
Copy link to clipboard
Copied
Then how did you get the result of 98% in the screenshot above?
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);
Copy link to clipboard
Copied
Change the last line to:
else event.value = 1-(a/b);
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:
Copy link to clipboard
Copied
You need to divide by the total number, not the total number plus the sum.
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.
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);
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?
Figure should be 5.34% at the bottom?
Copy link to clipboard
Copied
10 out of 534 is not 5.34%... It's 1.87%.
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.