Copy link to clipboard
Copied
I'm having a difficult time figuring out a formula for my pdf. There are two different ones that I need.
1. If "Field A" is 1 then take it times $X.XX if "Field A" is > 1 then take it times $XX.XX
2. If "Field B" is 1 then take it times $price1; if "Field B" is 2 then take it times $price2; if "Field B" is 3 or greater then take it times $price3
Thanks for your help!
Copy link to clipboard
Copied
OK, that's very simple. Use something like this code as the custom calculation for "Total Field A":
var price1 = 10;
var price2 = 20;
var qty = Number(this.getField("Field A").valueAsString);
if (qty==0) event.value = 0;
else if (qty==1) event.value = price1;
else event.value = price2 * qty;
You can adjust that code for the B fields, too.
Copy link to clipboard
Copied
What do you mean by "take it", exactly? Are you talking about changing the same field's value (A or B), or another field?
Copy link to clipboard
Copied
Here it is a little clearer.
1. If "Field A" is 1 then "Field A" times $X.XX if "Field A" is > 1 then "Field A" times $XX.XX
2. If "Field B" is 1 then "Field B" times $price1; if "Field B" is 2 then "Field B" times $price2; if "Field B" is 3 or greater then "Field B" times $price3
Copy link to clipboard
Copied
That is problematic because you've basically described a circular calculation. Let's take scenario 1, for example. Let's say the first price is 10 and the second is 20, and the initial value of field A is 1.
So as per your description it now becomes 10. Next time the calculations are updated (which is each time any field in the file is edited!), the value of A is 10, so it is now 10 * 20 = 200. Next time it will be 200 * 20 = 4000, etc., etc..
Do you see the issue there? You have to separate the two things. One field should be used for the quantity, and another for the total price. You can't combine the two.
Copy link to clipboard
Copied
This formula is in the "Total Field" at the end of the row. So the first row has a "Field A" where the customer puts in the quantity of product they want. If that number is 1 then "Field A" times $price1 and the answer is displayed in "Total Field A" at the end of the row. If the number entered in "Field A" is 2 or higher, then "Field A" times $price2 and that answer is displayed in "Total Field A" at the end of the row.
Same way with the "Field B" row. There is a "Total Field B" at the end of that row. The formula is in that box and calculates depending on what number is entered into "Field B" box.
Copy link to clipboard
Copied
OK, that's very simple. Use something like this code as the custom calculation for "Total Field A":
var price1 = 10;
var price2 = 20;
var qty = Number(this.getField("Field A").valueAsString);
if (qty==0) event.value = 0;
else if (qty==1) event.value = price1;
else event.value = price2 * qty;
You can adjust that code for the B fields, too.
Copy link to clipboard
Copied
Thanks! You're a genius!

