6 Replies Latest reply on Mar 23, 2015 9:02 AM by gkaiseril

# Summation Problem.

I have a series of fields that I would like to sum. I've tried using the script below to hide the field if all of the corresponding fields are blank and also perform the calculation if one of the fields is left out. However, I would like to re-write or figure out a script that allows the field to perform all of the above said functiona and also show a value of "0" if the function is validated as true.

Box 1: User Input

Box 2: User Input

Box 3: Box 1 - Box 2

Box 4  User Input

Box 5: User Input

Box 6: Box 4 + Box 6

var v1 = getField("Box 1").value!="" ? getField("Box 1").value : 0;

var v2 = getField("Box 2").value!="" ? getField("Box 2").value : 0;

var v3 = getField("Box 3").value!="" ? getField("Box 3").value : 0;

var v4 = getField("Box 4").value!="" ? getField("Box 4").value : 0;

var v5 = getField("Box 5").value!="" ? getField("Box 5").value : 0;

var v6 = getField("Box 6").value!="" ? getField("Box 6").value : 0;

event.value = ((v1+v2+v3+v4+v5+v6) !==0)?(v1+v2+v3+v4+v5+v6):"";

• ###### 1. Re: Summation Problem.

So what are you asking, exactly? Is this code not working correctly? It looks fine, if a bit cumbersome.

• ###### 2. Re: Summation Problem.

I think your fieldname should be "Box1" etc.. and not "Box 1" with blank. I thin the space is the Problem.

• ###### 3. Re: Summation Problem.

Field names can have spaces in them. As long as they are spelled exactly the same in the script as they are in the file that is not a problem.

• ###### 4. Re: Summation Problem.

i'm self newbee in Acrobat JavaScript, but in most other programing languages i know it isn't possible. But thank your for your response

• ###### 5. Re: Summation Problem.

A variable name in JS can't have spaces in it, but a field name is just a string. It can be pretty much whatever you want it to be.

• ###### 6. Re: Summation Problem.

Are you sure you want Box 6 to be the sum of Box 4 and Box 6?

This is known as a circular reference and Box 6 will increase in by its value with each calculation.

Have you tired the calculation?

If so, what is not working?