Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Need a dropdown field selection to unhide a 2nd dropdown field displaying conditional choice options

Explorer ,
Jul 26, 2021 Jul 26, 2021

Copy link to clipboard

Copied

Hello all!

 

So been at this for several hours over the weekend into today.  Still very new to javascript world and using it to customize forms, and have run into a wall so looking for some community help.  Super grateful if anyone can provide a little form guidance or scripting help or even let me know if what i need is even possible before I pull all my hair out!

 

Here is an overview of my field lables and options:

 

Dropdown field one label= "Vehicle1Category"
Dropdown field two label= "Vehicle1Subcategory" 

 

Under "Vehicle1Category" field, I have 5 available options to choose (technically 6 but "-Select Vehicle Category-" option is just so the default option displays as sort of a tool tip):

"-Select Vehicle Category",

"Bus"

"Car"

"Cargo Van"

"Mini Van"

"Other/Not Listed"

"Passenger Van

"SUV"

"Truck"

"Van"

"Trailer"

 

I'm wanting dropdown field two ("Vehicle1Subcategory) to be conditional upon a selection in dropdown field 1 ("Vehicle1Category").  Furthermore I'd like the "Vehicle1Subcategory" field to stay hidden, and made visible (and required) only if 2 of the specific option selections in the "Vehicle1Category" dropdown field are selected.  Any other option selected in that "Vehicle1Category" dropdown will keep the "Vehicle1subcategory" field hidden and not required.

 

The options that I want to trigger "Vehicle1subcategory" to be made visible and required are either "Truck" or "Trailer"

 

For example, when a person selects option "Truck" under "Vehicle1Category" then the second dropdown field becomes visible and required and only has following conditional options to choose from based on that "Truck" selection: 

 

"-Select Truck Type-"

"Car Carrier"

"Flatbed Truck

"Food/Catering/Lunch Truck"

"Other/Not Listed"

"Truck Tractor"

"Tow Truck"

 

Then when a person selects option "Trailer" under "Vehicle1Category", the second dropdown field becomes visible and required, and only has following conditional options to choose from based on that "Trailer" selection: 

 

"-Select Trailer Type-"

"Auto Hauler"

"Flatbed Trailer"

"Goose Neck Trailer"

"Horse or Live Stock Trailer"

"Refrigerated Dry Freight Trailer"

"Travel Trailer"

"Utility Trailer"

"Other/Not Listed"

 

I was able to work through and piece together my attempt at scripting above from several forums and have following below entered in the Properties>Validate>Run custom validation script.
If any one can help me with this would be so awesome!

 

if(event.value==""){this.getField("Vehicle1Type").setItems([""]);};

 

var aray4=[[""-Select Trailer Type-""],[""Auto Hauler""],[""Flatbed Trailer""],[""Goose Neck Trailer""],[""Horse or Live Stock Trailer""],[""Refrigerated Dry Freight Trailer""],[""Travel Trailer""],[""Utility Trailer""],[""Other/Not Listed""]]; if(event.value=="Truck"){this.getField("Vehicle1Type").setItems(aray4);};
var aray5=[[""-Select Trailer Type-""],[""Auto Hauler""],[""Flatbed Trailer""],[""Goose Neck Trailer""],[""Horse or Live Stock Trailer""],[""Refrigerated Dry Freight Trailer""],[""Travel Trailer""],[""Utility Trailer""],[""Other/Not Listed""]]; if(event.value=="Trailer"){this.getField("Vehicle1Type").setItems(aray5);};

 

Any help would be much appreciated including where best to insert the script.  Thanks!

 

TOPICS
General troubleshooting, How to, JavaScript, PDF forms

Views

45

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
Adobe Community Professional ,
Jul 26, 2021 Jul 26, 2021

Copy link to clipboard

Copied

Read these articles, they explain how to do pretty much exactly what you want (except for the visibility), and provide examples.  You can add the visibility after getting the other selection behaviors to work.

 

https://acrobatusers.com/tutorials/change_another_field/

https://acrobatusers.com/tutorials/js_list_combo_livecycle/

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm 

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm

 

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

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
Adobe Community Professional ,
Jul 26, 2021 Jul 26, 2021

Copy link to clipboard

Copied

There is more then 5 or even 6 choices 🙂

You said second field is labeled "Vehicle1Subcategory" and yet in code you use "Vehicle1Type"?

In field "Vehicle1Category" properties->options tab check "Commit selected value immediately".

Use code as "Validation script" and if you have different name for second field replace it in code:

if(event.value=="Truck"){
this.getField("Vehicle1Subcategory").display = display.visible;
this.getField("Vehicle1Subcategory").required = true;
this.getField("Vehicle1Subcategory").clearItems();
this.getField("Vehicle1Subcategory").setItems([["-Select Truck Type-"],["Car Carrier"],["Flatbed Truck"],["Food/Catering/Lunch Truck"],["Other/Not Listed"],["Truck Tractor"],["Tow Truck"]]);}

else if(event.value=="Trailer"){
this.getField("Vehicle1Subcategory").display = display.visible;
this.getField("Vehicle1Subcategory").required = true;
this.getField("Vehicle1Subcategory").clearItems();
this.getField("Vehicle1Subcategory").setItems([["-Select Trailer Type-"],["Auto Hauler"],["Flatbed Trailer"],["Goose Neck Trailer"],["Horse or Live Stock Trailer"],["Refrigerated Dry Freight Trailer"],["Travel Trailer"],["Utility Trailer"],["Other/Not Listed"]]);}
else {
this.getField("Vehicle1Subcategory").display = display.hidden;
this.getField("Vehicle1Subcategory").required = false;
this.getField("Vehicle1Subcategory").clearItems();}

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
Explorer ,
Jul 27, 2021 Jul 27, 2021

Copy link to clipboard

Copied

LATEST

OMG TY TY TY once again!!!

 

Your awesome!  It worked perfect!  🙂

 

And good catch!  Sorry for the confusion with dropdown field two label.  Originally I had dropdown field two labeled as "Vehicle1Type" in my scripting attempts, but decided probably be better I change label to "Vehicle1Subcategory" to provide further clarity when posting to forum regarding the functionality/scripting I needed help with.

 

Appreciate your help and expertise once 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