Skip to main content
Participant
March 26, 2019
Answered

Dropdown box selection affecting other dropdown box selections

  • March 26, 2019
  • 1 reply
  • 1229 views

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!

This topic has been closed for replies.
Correct answer try67

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.

1 reply

try67
Community Expert
Community Expert
March 26, 2019

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?

Participant
March 26, 2019

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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 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.