Skip to main content
Known Participant
March 2, 2023
Question

Show/hide not behaving as expected

  • March 2, 2023
  • 1 reply
  • 1593 views

I'm having an issue making a dropdown field appear depending on what is chosen in another dropdown and I don't know how to rectify it, so any help would be gratefully received. I am a novice with all this, so please keep any replies simple - thank you.

Part 1 - this works perfectly

A is the document Title and there are 3 options in the dropdown

B is a dropdown on page 2. This dropdown must only be visible if option 1 or 3 from the Title dropdown A is chosen.

 

Part 2 - this also works perfectly

B has 6 options in its dropdown, and each option makes other fields appear on the document. When a selection is made, dropdown B is hidden.

 

My problem is when I try and put them together. Regardless of what option is chosen in A, Dropdown B is visible. I think something is conflicting, but I don't know where or what!

 

In the custom calculation script box of dropdown B, I have this that makes Part 1 work:

if (this.getField("ContractTitleA").value == "Abonnement Global Services"){

(this.getField("DropdownB").display = display.visible;}

else if (this.getField("ContractTitleA").value == "Abonnement Connect – Relay Hub"){

(this.getField("DropdownB").display = display.visible;}

else{

event.target.display = display.hidden;

}

 

followed by this (only showing 2 lines here) for Part 2:

 

if (this.getField("DropdownB").value == "Equipement(s) auto-installable(s)"){

event.target.display = display.hidden;}

 

else if (this.getField("Installation choice_es_:prefill").value == "Machine à affranchir déjà installée"){

event.target.display = display.hidden;}

 

else{

event.target.display = display.visible;

 

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
March 2, 2023

Are those two sections of code in the same script? If so, the second part should not be in the calculation script for "DropdownB". 

 

In a calculation script, the field the script is on is never acquired with "this.getField".

 

Replace this.getField("DropdownB").display with event.target.display

Replace this.getField("DropdownB").value with event.value

 

But this is only part of the problem. Both parts of the code conflict, because both set the visibility of "DropdownB"

The code needs to be combined so they don't conflict. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
jlehaneAuthor
Known Participant
March 2, 2023

Yes they are in the same script (👉novice here👈)

I thought the conflict was because of the visibility on Dropdown B, but I don't know how to fix the problem. How would you combine it?

I will make the changes you have already suggested - thank you for these.

Thom Parker
Community Expert
Community Expert
March 2, 2023

I think you need to re-think your approach. What you really have here is a logic problem. 

I'd suggest creating a table of input variables VS input values, where the desired result is at the intersection. Once you have that, it is a simple step to build out the logic that will produce the desired results. 

 

Basically it will break down into 

1. a list of input values that result in visible

2. a list of input values that result in hidden. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often