Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- Acrobat SDK
- >
- Struggling with nested if statement

Feb 25, 2020

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.

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);
}
```

TOPICS

Acrobat SDK and JavaScript,
How to,
PDF forms

Community Guidelines

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

Feb 25, 2020

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.

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);
}
```

TOPICS

Acrobat SDK and JavaScript,
How to,
PDF forms

Community Guidelines

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

jasons35699793

Feb 25, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/td-p/10946916
11
Replies
11

Feb 25, 2020

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.

Community Guidelines

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

Reply

Loading...

try67

Feb 25, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10947067#M7441
Feb 26, 2020

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);

Community Guidelines

Reply

Loading...

jasons35699793

Feb 26, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10948046#M7442
Feb 26, 2020

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

Community Guidelines

Reply

Loading...

try67

Feb 26, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10948051#M7443
Feb 26, 2020

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

Community Guidelines

Reply

Loading...

jasons35699793

Feb 26, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10948313#M7444
Feb 26, 2020

Copy link to clipboard

Copied

You can use:

if ((Z == "X-SHADED" || Z == "AE") && B > D && B < A) {

Community Guidelines

Reply

Loading...

Bernd Alheit

Feb 26, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10948327#M7445
Feb 26, 2020

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);

Community Guidelines

Reply

Loading...

jasons35699793

Feb 26, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10948464#M7446
Feb 26, 2020

Copy link to clipboard

Copied

No, it's the line before that. if must be followed by round parentheses, not curly ones.

Community Guidelines

Reply

Loading...

try67

Feb 26, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10948652#M7447
Feb 26, 2020

Copy link to clipboard

Copied

Why does you use if { ?

Community Guidelines

Reply

Loading...

Bernd Alheit

Feb 26, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10948699#M7448
Feb 26, 2020

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/

**Thom Parker**- Software Developer at PDFScripting.com- Use the Acrobat JavaScript Reference Early and Often

Community Guidelines

Reply

Loading...

Thom Parker

Feb 26, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10948833#M7449
Feb 26, 2020

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

Community Guidelines

Reply

Loading...

jasons35699793

Feb 26, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10948942#M7450
Feb 28, 2020

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);
}
```

**Thom Parker**- Software Developer at PDFScripting.com- Use the Acrobat JavaScript Reference Early and Often

Community Guidelines

Reply

Loading...

Thom Parker

Feb 28, 2020
0
/t5/acrobat-sdk/struggling-with-nested-if-statement/m-p/10953071#M7451
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.