## Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.

## Adobe Support Community

• Form fields not calculating correctly & issue with...

# Form fields not calculating correctly & issue with "If/Then" statements

New Here ,
Jul 27, 2021 Jul 27, 2021

Copy link to clipboard

Copied

I have been wracking my brain and none of the people I've sought help from have been able to help, so hopefully you guys can tell me what the heck I'm doing wrong. I am self taught in Java Script, so I am kinda winging it here!

I’m creating an application for new construction and this portion of the application asks what the irrigation needs are.

Here is a screenshot of what the section looks like so far and I attached the actual page in case this is too difficult to read:

IRR1 – just a basic field to enter a number for square footage.

IRR2, IRR3, IRR4 – Also just number entries.

IRR5 – has a basic formula for each tree is equivalent to 17 sq. ft. of irrigation area. (Currently I'm using simplified field notation, that formula is: IRR2*17)

IRR6 – Shrub = 6 sq. ft. of irrigation area. That formula is: IRR3*6

IRR7 – Perennials = 3 sq. ft. of irrigation area. That formula is: IRR4*3

SqFtTotal – formula: I used the “Value is”, selected “sum” and then I selected fields IRR1, IRR5, IRR6, IRR7

GPM (gallons per minute) – using Simplified field notation, that formula is: (SqFtTotal/43560)*23 …. So, it’s converting the sq. ft. in to acreage and multiplying 23 GPM per acre.

1. First problem lies here in the GPM formula. IRR5, IRR6, & IRR7 are all calculated values and IRR1 is just an entered number. GPM will not calculate it at all, but when I delete the value from IRR1, it suddenly calculates GPM for the value that WAS in IRR1. It also will not calculate IRR2, IRR3, or IRR4 unless there is at least a value of “0” in them. Not all applicants complete the tree/shrub/peren section, so I need those areas to be set at “0” if nothing is entered in that field.

MeterSize – The if/then statement… I did a “Custom calculation script” for this one…

1. First one I tried:
var MeterSize=this.getField("GPM").value;
if(GPM=0)event.value=0;
if((GPM>0)&&(GPM<25))event.value="3/4 in.";
if((GPM>24)&&(GPM<51))event.value="1/2in.";
if((GPM>50)&&(GPM<121))event.value="1 in.";
if((GPM>120)&&(GPM<161))event.value="2 in.";
if(GPM>160)event.value="3 in.";
2. Second one I tried:

var MeterSize=this.getField("GPM").value;
if((GPM>0)&&(GPM<25))event.value="3/4 in.";
if((GPM>24)&&(GPM<51))event.value="1/2in.";
if((GPM>50)&&(GPM<121))event.value="1 in.";
if((GPM>120)&&(GPM<161))event.value="2 in.";
if(GPM>160)event.value="3 in.";
else event.value=0;

So just the “0” event is different because I thought that might have something to do with why it’s not working.

I'm thinking maybe the statements aren't working because I'm telling it to put in a "value" but the value is actually text. However, when I used decimals it didn't work either.

I plan to make IRR5, IRR6, IRR7, & SqFtTotal all invisible, and GPM and Meter Size will be Read Only.

Ultimately, I am trying to get it to automatically determine a meter size based on the entered information.

Thanks for the help!!

TOPICS
General troubleshooting, How to, JavaScript, PDF forms

Views

38

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
3 Replies 3
LEGEND ,
Jul 27, 2021 Jul 27, 2021

Copy link to clipboard

Copied

I can't see for sure but it looks as if you are making the popular error:

if ( Gpm = 0 ) ..,

if ( Gpm == 0) ...

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
LEGEND ,
Jul 27, 2021 Jul 27, 2021

Copy link to clipboard

Copied

Also your final "else" applies only to the line above it, it isn't a catch all for everything that went before. So you get 0 for every input value below 160.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jul 27, 2021 Jul 27, 2021

Copy link to clipboard

Copied

LATEST

1. Problem with GPM is in field calculation order, Select "Prepare form" tool and click on "More" then "Set field calculation order" now put "SqFtTotal" above "GPM".
2. As mentioned, use double == when comparing, also very obvious mistake is you called variable "MeterSize" but then you use field name in script "GPM".
Change "GPM" to "MeterSize" and add "else" something like this:

``````var MeterSize = this.getField("GPM").value;
if(MeterSize == 0)event.value = 0;
else if((MeterSize>0)&&(MeterSize<25))event.value="3/4 in.";
else if((MeterSize>24)&&(MeterSize<51))event.value="1/2in.";
else if((MeterSize>50)&&(MeterSize<121))event.value="1 in.";
else if((MeterSize>120)&&(MeterSize<161))event.value="2 in.";
else if(MeterSize>160)event.value="3 in.";``````

It will probably be when you add code but make sure "MeterSize" is last in field calculation order.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources