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

How do I calculate form fields?

Community Beginner ,
Nov 20, 2016 Nov 20, 2016

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.

2016-11-21 01_56_59-My Body Guru Order Form_161121.pdf - Adobe Acrobat Pro DC.png

Thank you.

!

659
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 ,
Nov 20, 2016 Nov 20, 2016

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;

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 ,
Nov 20, 2016 Nov 20, 2016

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.

2016-11-21 11_49_45-My Body Guru Order Form_161121.pdf - Adobe Acrobat Pro DC.png

Thank you so very much, 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 ,
Nov 21, 2016 Nov 21, 2016
LATEST

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;

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