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.
MeterSize – The if/then statement… I did a “Custom calculation script” for this one…
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!!
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 ) ..,
instead of
if ( Gpm == 0) ...
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.
Copy link to clipboard
Copied
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.