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

Dropdown box selection affecting other dropdown box selections

New Here ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

Copied

Hi all. I'm relatively new to the whole JavaScript in Adobe Acrobat thing so I'll try to be as concise as possible.

Simply put, I have created a dropdown menu named "Banklist" with 2 options "Bank 1" and "Bank 2".

  • When "Bank 1" is selected a second dropdown (named "MCCCODES") appears beside it with a number of codes which based off of the code selection will populate a field with a specific percentage.
  • If "Bank 2" is selected the second dropdown remains hidden.

I used the following Validation script and everything works as I had hoped:

if(event.value =="Bank 1"){

this.getField("MCCCODE").display = display.visible;

this.getField("Test1").display = display.visible;

}

else{

this.getField("MCCCODE").display=display.hidden;

this.getField("Test1").display=display.hidden;

}

if(event.value =="Bank 2"){

this.getField("Text5test").display = display.visible;

}

else{

this.getField("Text5test").display=display.hidden;

}

My problem is that if I click on a dropdown in an unrelated area of the form (named Combo Box01 for example), as soon as I select an option it automatically causes "Bank 1" to appear and the second hidden box appears as well. Does anyone have any ideas as to what is causing unrelated dropdowns to affect each other?

I'm sure I'm missing something simple but for the life of me I can not think of what it is.

Thank you in advance for all your help. This is driving me crazy!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

245

Likes

Translate

Translate

Report

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

Community Expert , Mar 26, 2019 Mar 26, 2019

You've made a classic mistake that many people do. You've used the value assignment operator ( = ) in your if-condition instead of the value comparison operator ( == ). Change it in both statements and it should solve the issue.

Also, you used the wrong method names. It's getField, not getfield, and setItems, not setitems. Remember that JavaScript is case-sensitive! However, that first line doesn't really do anything, really, so you should remove it entirely.

Likes

Translate

Translate
Community Expert ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

Copied

Do you have any calculation script somewhere in your file that sets the options of this drop-down field, or reset the form, or something like that?

Likes

Translate

Translate

Report

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 ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

Copied

I have the following Calculation scripts but they are both in fields that would be populated by selecting an option from the dropdowns. No other calculation scripts anywhere in the file.

var v = this.getField("MCCCODE").value;

if (v=="5962") event.value = "0.100%";

else if (v=="5966") event.value = "0.100%";

else if (v=="7995") event.value = "0.100%";

else if (v=="4813") event.value = "0.100%";

else if (v=="7273") event.value = "0.100%";

else if (v=="5967") event.value = "0.350%";

else if (v=="1750") event.value = "0.010%";

else if (v=="3000-3298") event.value = "0.010%";

else if (v=="4511") event.value = "0.010%";

else if (v=="4112") event.value = "0.010%";

else if (v=="4131") event.value = "0.010%";

else if (v=="4411") event.value = "0.010%";

else if (v=="4722") event.value = "0.010%";

else if (v=="5712") event.value = "0.010%";

else if (v=="5734") event.value = "0.010%";

else if (v=="5963") event.value = "0.010%";

else if (v=="5964") event.value = "0.010%";

else if (v=="5968") event.value = "0.010%";

else if (v=="5969") event.value = "0.010%";

else if (v=="6051") event.value = "0.010%";

else if (v=="7012") event.value = "0.010%";

else if (v=="7297") event.value = "0.010%";

else if (v=="7922") event.value = "0.010%";

else if (v=="Exceptions") event.value = "0.025%";

else event.value="";

and:

if (this.getField("Banklist").value = "Bank1"){

this.getfield("Banklist")

}

else if (this.getField("Banklist").value = "Bank2"){

this.getField("Text5test").setitems(["","0.50%"])

}

I'm sure there is a better way to write the first script but it works at least for the time being at least.

Likes

Translate

Translate

Report

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 ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

Copied

You've made a classic mistake that many people do. You've used the value assignment operator ( = ) in your if-condition instead of the value comparison operator ( == ). Change it in both statements and it should solve the issue.

Also, you used the wrong method names. It's getField, not getfield, and setItems, not setitems. Remember that JavaScript is case-sensitive! However, that first line doesn't really do anything, really, so you should remove it entirely.

Likes

Translate

Translate

Report

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 ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

Copied

LATEST

You are my hero and most deserving of the MVP designation! That totally fixed the issue.

Thank you so much for the help. It was driving me insane! I don't think I'll forget about == vs = and case sensitivity in the future.

Thank you again!

Likes

Translate

Translate

Report

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