9 Replies Latest reply on Apr 28, 2014 8:08 AM by PleaseHelpMe

# Need Help With Variable Field Calculation

I am putting together a form and would like to have the calculations worked out for the people using the form to minimize errors. The premise of the equation is ...

If suction pressure reads in PSIG, subtract from discharge to get total feet.

If suction pressure reads in Vacuum, add to the discharge pressure to get total feet.

My fields are set up as...

Discharge Pressure PSIG

Fixed           // fixed value of 2.31

Discharge Calc

Suction Pressure PSIG

Fixed 1        // fixed value of 2.31

V Suction Calc

Suction Vacuum

Fixed 2          // fixed value of 1.13

S Suction Calc

Total Feet

In the form, I have the following field equations set up:

Discharge Pressure PSIG x Fixed = Discharge Calc

Suction Pressure PSIG x Fixed 1 = V Suction Calc

Suction Vacuum x Fixed 2 = S Suction Calc

So, I have assigned each of the fields I need to work with a variable name

var v1 = Discharge Calc

var v2 = V Suction Calc

var v3 = S Suction Calc

var v4 = Suction PSIG

var v5 = Suction Vacuum

What I think should work logically would be the follow:

If v4 = 0, then v1+v3

if v5 = 0, then v1-v2

So, can you help me fix my script for the Total Feet field, please? I have no idea what I'm doing! This is what I have so far:

var v1 = getField("Discharge Calc").value;

var v2 = getField("V Suction Calc").value;

var v3 = getField("Suction Calc").value;

var v4 = getField("Suction PSIG").value;

var v5 = getField("Suction Vacuum").value;

if (v4=0)

event.value = (v1+v3);

if (v=5)

event.value = (v1-v2);

Many thanks for your help and have a nice day.

• ###### 1. Re: Need Help With Variable Field Calculation

This:

if (v4=0)

Should be:

if (v4==0)

And this:
if (v=5)

Is incorrect. There's no variable in your code called "v". Also, you're using the wrong operator here as well.

• ###### 2. Re: Need Help With Variable Field Calculation

Thanks a bunch! Ok, so now it reads:

var v1 = getField("Discharge Calc").value;

var v2 = getField("V Suction Calc").value;

var v3 = getField("S Suction Calc").value;

var v4 = getField("Suction PSIG").value;

var v5 = getField("Suction Vacuum").value;

if ( v4 == 0 )
event.value = ( v1 + v3 );
else if ( v5 == 0 )
event.value = ( v1 - v2);

But it still doesn't calculate.

It's entirely possible it's my logic that's off. That plus this is my first attempt at a calculation AND javascript.

• ###### 3. Re: Need Help With Variable Field Calculation

"Doesn't work" doesn't mean much... What exactly happens? Do you get no result? The wrong result?

Are there error messages in the JS console?

• ###### 4. Re: Need Help With Variable Field Calculation

No errors in JS console. When I change the values in v4 and v5, the value does not change in the total field. I have some other fields that change dependant on what is in v4 or v5 and those are working when I change the value but this field does not.

• ###### 5. Re: Need Help With Variable Field Calculation

Change the first lines from this:

var v1 = getField("Discharge Calc").value;

To this:

var v1 = +this.getField("Discharge Calc").value;

• ###### 6. Re: Need Help With Variable Field Calculation

Good morning, Gilad. I made the changes requested on each of the first line. The value does not change in the total field. No errors in JS console. Thank you for the help, though.

• ###### 7. Re: Need Help With Variable Field Calculation

Can you share the file in question, via Acrobat.com, Dropbox, or privately by email?

• ###### 8. Re: Need Help With Variable Field Calculation

You could have an issue with the calculation order.

• ###### 9. Re: Need Help With Variable Field Calculation

Gilad D (try67) fixed the problem for me.