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

Hidding/making visible multiple dropdowns based a dropdown selection

New Here ,
May 02, 2019 May 02, 2019

Copy link to clipboard

Copied

Hello ,

I have never really coded before so I was hoping someone could help. I am trying to hide/view dropdowns based on a selection made in a drop down.

Ex. I have a dropdown (dropdown 1: Sujet) containing values: Consommateurs, Articles, Recettes, Menus, Distribution, Production, Compilation and dropdowns with respective names (ex. dropdown 2: Consommateurs, dropdown 3: Articles etc.). I would like that if the value consommateurs is selected in the dropdown 1 (sujet) that all the other dropdowns are hidden except for dropdown 2 named consommateurs. I have created some code based on what I have found on the forum, however it only seems to hide/show the first dropdown based on my selection. All the rest stay visible. Any help would be greatly appreciated! Thanks in advance!

switch(event.value){

case "Consommateurs":

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

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

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

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

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

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

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

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

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

   break;

case "Recette":

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

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

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

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

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

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

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

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

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

   break;

case "Articles":

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

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

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

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

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

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

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

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

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

   break;

case "Menus":

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

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

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

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

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

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

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

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

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

   break;

case "Distribution":

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

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

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

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

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

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

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

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

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

   break;

case "Compilation":

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

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

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

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

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

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

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

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

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

   break;

default:

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

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

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

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

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

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

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

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

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

TOPICS
PDF forms

Views

854

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 ,
May 02, 2019 May 02, 2019

Copy link to clipboard

Copied

I would add some kind of debugging command to show which case is being executed. My guess is you're always falling into the "default" section because of a mismatch between the actual value of your field and the value in your code.

Also, this code can be greatly simplified if you first hide all the fields by default and then just add a command to show the one field you're interested in based on the selection.

Votes

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 Beginner ,
May 04, 2019 May 04, 2019

Copy link to clipboard

Copied

Thank you for the feedback! How can I debug the code? I can't find a debugging window in Adobe. I tried hidding the dropdowns initially but I realized that once a dropdown was made visible it stays visible even if I changed my selection after. Any idea what I am doing wrong? Thank you.☺

Votes

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
LEGEND ,
May 04, 2019 May 04, 2019

Copy link to clipboard

Copied

Acrobat and Reader include a JavaScript console within the application. For Acrobat one can use the key combination "<Ctrl> + J" to bring up the console or find it under the "Prepare Forms" tool in the "More" section. One also has some console object  and its methods

Votes

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 ,
May 05, 2019 May 05, 2019

Copy link to clipboard

Copied

Before the switch add following lines:

console.show();

console.println("value: '" + event.value + "'");

Votes

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 Beginner ,
May 05, 2019 May 05, 2019

Copy link to clipboard

Copied

Thank you both for the tips on debugging! I have been playing around and I keep getting the following errors

TypeError: this.getField(...) is null

119:Field:Keystroke

TypeError: this.getField(...) is null

9:Field:Keystroke

It's as though it does not recognize my dropdowns   I've renamed by dropdowns to be exactly what the name is so I am not sure what the issue is.

Votes

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 ,
May 06, 2019 May 06, 2019

Copy link to clipboard

Copied

Double-check it. Remember that JavaScript is case-sensitive. So if the field is called "Text1" and you entered "text1" in your code, it won't work.

Votes

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 Beginner ,
May 06, 2019 May 06, 2019

Copy link to clipboard

Copied

Thank you so much! I tried and no luck

Here is the file link. Can you see if I am missing something?

Dropbox - TEST Drop Down.pdf - Simplify your life

Thanks in advance!

Votes

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 ,
May 06, 2019 May 06, 2019

Copy link to clipboard

Copied

You don't have a field with the name "Rapports".

Votes

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 ,
May 06, 2019 May 06, 2019

Copy link to clipboard

Copied

As mentioned, you got the names of the fields wrong. It's not the text that you see in them, it's what you see written on top of them in Prepare Form mode:

Votes

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 ,
May 06, 2019 May 06, 2019

Copy link to clipboard

Copied

And if you removed the fields with those names for testing purposes then you have to also remove (or comment out) the code that tries to access them, or it will result in an error.

Votes

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 ,
May 06, 2019 May 06, 2019

Copy link to clipboard

Copied

Thank you!

Votes

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 ,
May 06, 2019 May 06, 2019

Copy link to clipboard

Copied

LATEST

Thank you!

Votes

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