Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

IF / AND statement question

Contributor ,
Sep 29, 2016 Sep 29, 2016

when using an if(  ) && ( ) statement, is it permissible to test for two different conditions. Meaning, can I say, "If the apple is red, and if the car is blue, then..."? Or, does it have to be something like, "If the apple is red and the apple is large"?

The below code is not working as I would like, and I'm wondering if the problem is the && statement.

Situation: There are two classes. Class I and Class 2 ("Title"). Class I gets life insurance at 3x annual income, up to $1,500,000. Class 2 gets life insurance at 3x annual income, up to $600,000. I have a dropdown list, "Title", with Class I and Class II to select, (returning 1 or 2). The calculable field is suppose to return the life insurance death benefit, depending on the conditions of the class and income. It is ignoring Class 2. In other words, I can type any amount of income when Class 2 is selected and the death benefit will blow past 600,000 and go all the way to 1,500,000.

Is my problem the way I'm using &&?

var a1 = getField("Income").value;   //annual income

var a2 = getField("Title").value;   //job class; either 1 or 2 numeric value

var v1 = a1*3;   //life insurance is 3x annual income

//if Class I and life insurance amount is < 1500000, then 3x annual income

if((a2 = 1) && (v1 < 1500000)) event.value = v1;

//if Class I and life insurance is > 1500000, then 1500000 (the max)  

else if((a2 = 1) && (v1 > 1500000)) event.value = 1500000;

//if Class I and life insurance amount is < 600000, then 3x annual income

else if((a2 = 2) && (v1 < 600000)) event.value = v1;

//if Class I and life insurance amount is > 600000, then 600000 max

else if((a2 = 2) && (v1 > 600000)) event.value = 600000;

Thanks for any help!

TOPICS
Acrobat SDK and JavaScript , Windows
821
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 29, 2016 Sep 29, 2016

Instead of this:

if((a2 = 1) && (v1 < 1500000)) event.value = v1;

Do this:

if ((a2 == 1) && (v1 < 1500000)) event.value = v1;

in all cases, and that should fix it.

Translate
LEGEND ,
Sep 29, 2016 Sep 29, 2016

Instead of this:

if((a2 = 1) && (v1 < 1500000)) event.value = v1;

Do this:

if ((a2 == 1) && (v1 < 1500000)) event.value = v1;

in all cases, and that should fix it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2016 Sep 30, 2016

The conditions can be whatever you want.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 30, 2016 Sep 30, 2016
LATEST

Thank you.

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