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

Conditional If/Else statement using two conditions

New Here ,
Sep 07, 2016 Sep 07, 2016

Hello,

I am trying to write a conditional if/else statement that puts a text value in a box 3 when specific conditions in box 1 and box 2 are met. Box 1 and 2 are drop down boxes with set values.

I've tried searching all over the web and have probably rewritten it at least 10 different times. At one point I was able to get it working with only one of the boxes factored into the code but my computer crashed and I lost that part.

Here's what I have:

var n1 = this.getField("likelihood").value:

var n2 = this.getField("consequence").value;

if ((n1.value=='N/A') && (n2.value=='N/A')) {

     event.value = 'N/A'

} else if ((n1=='Not Likely') && (n2=='Insignificant') {

     event.value = 'Low'

}

This would continue on another 14 times to account for the various combinations that can be chosen using box 1 and box 2. I have also tried placing it in the 2nd combo box as an action item but still no luck. Any help would be much appreciated.

TOPICS
Acrobat SDK and JavaScript , Windows
1.8K
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 07, 2016 Sep 07, 2016

n1 and n2 are already the value of the fields, so why are you trying to access the value property again in the first if-statement?

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
New Here ,
Sep 07, 2016 Sep 07, 2016

Oops that's a typo. It should say n1 and n2 like the else if statement.

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 07, 2016 Sep 07, 2016

So post the actual code, and also specify where you're using it. The code you posted above should be used a custom calculation script of some field.

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
New Here ,
Sep 07, 2016 Sep 07, 2016

Here is the code:

var n1 = this.getField("likelihood").value;

var n2 = this.getField("consequence").value;

if ((n1=='N/A') && (n2=='N/A')){

    event.value = 'N/A'

} else if ((n1=='Not Likely') && (n2=='Insignificant')){

    event.value = 'LOW'

} else if ((n1=='Not Likely') && (n2=='Minor')){

    event.value = 'LOW'

} else if ((n1=='Not Likely') && (n2=='Moderate')){

    event.value = 'LOW'

} else if ((n1=='Not Likely') && (n2=='Major')){

    event.value = 'MEDIUM'

} else if ((n1=='Low Likelihood') && (n2=='Insignificant')){

    event.value = 'LOW'

} else if ((n1=='Low Likelihood') && (n2=='Insignificant')){

    event.value = 'LOW'

} else if ((n1=='Low Likelihood') && (n2=='Moderate')){

    event.value = 'MEDIUM'

} else if ((n1=='Low Likelihood') && (n2=='Major')){

    event.value = 'MEDIUM'

} else if ((n1=='Likely') && (n2=='Insignificant')){

    event.value = 'LOW'

} else if ((n1=='Likely') && (n2=='Minor')){

    event.value = 'MEDIUM'

} else if ((n1=='Likely') && (n2=='Moderate')){

    event.value = 'HIGH'

} else if ((n1=='Likely') && (n2=='Major')){

    event.value = 'HIGH'

} else if ((n1=='Highly Likely') && (n2=='Insignificant')){

    event.value = 'LOW'

} else if ((n1=='Highly Likely') && (n2=='Minor')){

    event.value = 'MEDIUM'

} else if ((n1=='Highly Likely') && (n2=='Moderate')){

    event.value = 'HIGH'

} else if ((n1=='Highly Likely') && (n2=='Major')){

    event.value = 'HIGH'

}

I had it in the validation script, moved it to custom calc script and still didn't work. It's being used in box 3 which should show the rating based on the choices in n1 and n2.

I have also tried using it in the second drop down box (n2) as an action item for mouse blur so it would update after the user made a choice in the last drop down.

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 07, 2016 Sep 07, 2016
LATEST

- Keep it as the custom calculation script.

- Add this line to the end of your code:

else event.value = "SOMETHING ELSE";

- Check the JS console for error messages.

If all of that fails then you'll need to share the file with us for additional help.

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