Copy link to clipboard
Copied
Hi Everyone,
How do I calculate a certain number of form fields? As you can see below, the shipping field; for every 1 to 12 items, the number should calculate R35. So, if there is 13 to 24 items it should calculate R70, and so on. How do I calculate this in the field properties? What is the formula for this?
This must be based on the quantity of the items number and NOT just based on the quantity fields number.

Thank you.
!
Copy link to clipboard
Copied
So regardless of the values entered in the Qty fields, if more than 12 of them are filled in with anything, then the value should be 70, otherwise it's 35 (and I'm assuming 0 if no fields are filled in)?
If so, and assuming the names of these fields are Qty1 to Qty24, you can use this code as the custom calculation script of the Shipping Total field:
var total = 0;
for (var i=1; i<=24; i++) {
if (this.getField("Qty"+i).valueAsString!="") total++;
}
if (total==0) event.value = 0;
else if (total<=12) event.value = 35;
else event.value = 70;
Copy link to clipboard
Copied
Hi try67,
Thank you for answering my question. We are almost there, but what I need here is the calculation for the numbers in the quantity fields and NOT the quantity fields boxes itself. For example, Qty1 is 8, Qty2 is 10, Qty3 is 5, and so on (see below for sample).
Can you provide me the calculation if the overall sum of Qty fields divided by 12 and for each 12 multiples the shipping field is calculated as R35, R70, R105, etc.
For example,
Total quantity is 83. 83 divided by 12 = 6.9 (so 7 when rounded to). 7 x R35 = R245
Hope this makes sense.

Thank you so very much, try67!
Copy link to clipboard
Copied
OK, that was not very clear from your original post... But try this code:
var total = 0;
for (var i=1; i<=24; i++) {
total+=Number(this.getField("Qty"+i).valueAsString);
}
event.value = Math.round(total/7)*35;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now