Copy link to clipboard
Copied
I need to create an if then statement ot check multiple variables.
I have a 100yr floodplain (100yr) A (500yr) a (HAG) a (LAG) and a (Zone)
I need to calculate min FF if Zone = x-shaded min ff = HAG + 1 If LAG is below 500 yr & above 100 yr: Min FF must be at least = to 500 yr
If LAG is below 500 yr & 100 yr BFE: Min FF must be at least 2’ above 500
I started by creating varialbe for LAG HAG 100yr and 500yr but not sure how to check the zone and where to go from there.
var A = this.getField ("500yr").value;
var B = this.getField ("LAG").value;
var C = this.getField ("HAG").value;
Var D = this.getField ("100yr").value;
var E = C + 1;
if(B > A)
Not even sure if I am on the right track with this any help is appreciated.
You need to study the core JS-syntax first.
This site offers a good introduction: https://www.w3schools.com/js/default.asp
Here's how the code is written with indents and brackets.
The brackest are only necessary when there is more than one line in the "if" block. But I've shown them here for completeness.
I've also added extra parenthese around some of the comparison opertators to enforce the grouping/order of operations. This is very helpful when operator precedence is not obvious.
var Z = this.getField ("Zone").valueAsString; // Value as a string
var A = this.getField ("500yr").value; // Value as a number
var B
...
Copy link to clipboard
Copied
So this is a validation script?
What you need is not nested if-statements, necessarily, but to use logical operators, such as AND (&&) and OR (||) in your if-conditions.
Copy link to clipboard
Copied
Yes I'm just not sure I'm on the right track. I need to check min FF against zone if it is anything other than x or x-shaded which is a text value than min FF = HAG + 1 then it will check that the LAG is higher or lower than the 100yr and 500yr if it is lower then the value will be equal to 500 yr + 2 if it is Higher than min FF = 500yr.
here is waht I am thinking
var A = this.getField ("500yr").value;
var B = this.getField ("LAG").value;
var C = this.getField ("HAG").value;
Var D = this.getField ("100yr").value;
var E = C + 1;
if(B < A) && (B < D);
E = (A + 2);
Copy link to clipboard
Copied
You need to study the core JS-syntax first.
This site offers a good introduction: https://www.w3schools.com/js/default.asp
Copy link to clipboard
Copied
(function(){
// Get the feild values
var Z = this.getField ("Zone").valueAsString; // Value as a string
var A = this.getField ("500yr").value; // Value as a number
var B = this.getField ("LAG").value; // Value as a number
var C = this.getField ("HAG").value; // Vlaue as a number
Var D = this.getField ("100yr").value; // Value as a number
if (Z = "X-SHADED" OR "AE" OR "X-SHADED/AE" && B < A && B < D){
event.value = (A + 2);
}else if{ (Z = "X-SHADED" OR "AE" && B > D && B < A){
event.value = (A);
}else if{ (Z = "X")
event.value = (c + 1);
}
})();
I think I am gettign closer but still not quite there
Copy link to clipboard
Copied
You can use:
if ((Z == "X-SHADED" || Z == "AE") && B > D && B < A) {
Copy link to clipboard
Copied
Here is what I have so far
(function(){
// Get the field values
var Z = this.getField ("Zone").valueAsString; // Value as a string
var A = this.getField ("500yr").value; // Value as a number
var B = this.getField ("LAG").value; // Value as a number
var C = this.getField ("HAG").value; // Vlaue as a number
var D = this.getField ("100yr").value; // Value as a number
if ((Z == "X-SHADED" || Z == "AE" || Z == "X-SHADED/AE") && B < A && B < D){
event.value = (A + 2);
}else if{ ((Z = "X-SHADED" || Z == "AE") && B > D && B < A){
event.value = (A);
}else if{ (Z = "X")
event.value = (c + 1);
}
}})();
debugger is saying that I am missing an ( condition on line 12 which is event.value = (A);
Copy link to clipboard
Copied
No, it's the line before that. if must be followed by round parentheses, not curly ones.
Copy link to clipboard
Copied
Why does you use if { ?
Copy link to clipboard
Copied
First, you need to get the basic "if" syntax correct.
Its also very helpful to write the code with indents to show the nesting in a way that is easy to understand.
Here's an article on using the "if" statement.
https://www.acrobatusers.com/tutorials/conditional-execution/
Copy link to clipboard
Copied
Here is what I have now,
// Get the field values
var Z = this.getField ("Zone").valueAsString; // Value as a string
var A = this.getField ("500yr").value; // Value as a number
var B = this.getField ("LAG").value; // Value as a number
var C = this.getField ("HAG").value; // Value as a number
var D = this.getField ("100yr").value; // Value as a number
if ((Z == "X-SHADED" || Z == "AE" || Z == "X-SHADED/AE") && B < A && B < D)
event.value = (A + 2);
else if ((Z == "X-SHADED" || Z == "AE") && B > D && B < A)
event.value = (A);
else if (Z == "X")
event.value = (C + 1);
So far it appears to be working but I haven't tested it with all the necessary values yet. Thank you for helping me get this far
Copy link to clipboard
Copied
Here's how the code is written with indents and brackets.
The brackest are only necessary when there is more than one line in the "if" block. But I've shown them here for completeness.
I've also added extra parenthese around some of the comparison opertators to enforce the grouping/order of operations. This is very helpful when operator precedence is not obvious.
var Z = this.getField ("Zone").valueAsString; // Value as a string
var A = this.getField ("500yr").value; // Value as a number
var B = this.getField ("LAG").value; // Value as a number
var C = this.getField ("HAG").value; // Value as a number
var D = this.getField ("100yr").value; // Value as a number
if (((Z == "X-SHADED") || (Z == "AE") || (Z == "X-SHADED/AE")) && (B < A) && (B < D))
{
event.value = (A + 2);
}
else if (((Z == "X-SHADED") || (Z == "AE")) && (B > D) && (B < A))
{
event.value = (A);
}
else if (Z == "X")
{
event.value = (C + 1);
}