Skip to main content
October 17, 2016
Answered

Addition of numbers in text fields with a twist

  • October 17, 2016
  • 2 replies
  • 412 views

Hello every one

i have a pdf document that contains usual columns and rows having text fields for data entry.

First column contains items names and second column is for the quantity of each item. Condition is that one item e.g. item "A" can occupy ONE OR MORE THAN ONE ROW and the table contains more than one item.

What i need is calculate the total quantity of each item i.e. item "A", "B" and so on, separately in a different text field. But remember the cumber of rows occupied by each item may vary every time the table is filled. For more clarification the table is given below:

Item
Quantity
A5
A10
A15
B2
B4
B6

Thanks in advance

This topic has been closed for replies.
Correct answer try67

Let's say the fields are named Item1, Item2, etc., up to Item6 and Quantity1, Quantity2, etc.

You can use this code as the custom calculation script of the field that shows the total amount of "A" items:

var total = 0;

for (var i=1; i<=6; i++) {

    if (this.getField("Item"+i).valueAsString=="A") total+=Number(this.getField("Quantity"+i).valueAsString);

}

event.value = total;

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
October 17, 2016

Let's say the fields are named Item1, Item2, etc., up to Item6 and Quantity1, Quantity2, etc.

You can use this code as the custom calculation script of the field that shows the total amount of "A" items:

var total = 0;

for (var i=1; i<=6; i++) {

    if (this.getField("Item"+i).valueAsString=="A") total+=Number(this.getField("Quantity"+i).valueAsString);

}

event.value = total;

October 17, 2016

Thank You so very much try67 You solved the problem.