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;
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.
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.☺
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Before the switch add following lines:
console.show();
console.println("value: '" + event.value + "'");
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.
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.
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!
Copy link to clipboard
Copied
You don't have a field with the name "Rapports".
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:
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.
Copy link to clipboard
Copied
Thank you!
Copy link to clipboard
Copied
Thank you!