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

Creating a dynanic dropdown field that doesn't automatically display the default option in the box.

New Here ,
Aug 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

Hello, I am trying to create a drop down box that has the options within auto-filled based on the selection from the previous box. I found code that worked on the forums, but any time a choice is made, it will revert back to whatever choice is listed first within the code.

Dropdown box 1 custom calculation script is:

switch (event.value) {

case "Select:":

        this.getField("SubProvType").setItems(["Please Make a Selcetion In The Previous Box First!"]);

        break;

    case "Choice1":

        this.getField("SubProvType").setItems(["A","B","C","D"]);

        break;  

    case "Choice2":

        this.getField("SubProvType").setItems(["E","F","G","H"]);

        break;  

}

 

This will display the correct options in the second box, but if Choice1 is selected in the first box, then any choice made in the second box reverts back to "A" instantly. Is there something I can add to the code or some option that can be selected that will allow the chosen "Letter" to remain chosen, or will it always revert back to the first option listed in the code?

 

 

TOPICS
Acrobat SDK and JavaScript

Views

216

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 ,
Aug 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

I can't see "Letter" in your lists. You can set the selection only on one of the items in the list.

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 ,
Aug 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

If you're running this script as a custom calculation script in the "Select" field , You need to to add an additional line at the beginning of your script like this:

 

 

if (event.source && event.source.name=="myDropdown") {

switch (event.value) {

case "Select":

       this.getField("SubProvType").setItems(["Please Make a Selcetion In The Previous Box First!"]);

        break;

    case "Choice1":

        this.getField("SubProvType").setItems(["A","B","C","D"]);

        break;  

    case "Choice2":

        this.getField("SubProvType").setItems(["E","F","G","H"]);

        break;  
   } 
}

 

 

Just replace "myDropdown" with the actual name of your primary dropdown fieldname.

 

This will allow to make a choice in this field and then in the "SubProvType" field whatever you select from the list will stay selected and you can continue to work with other fields in your PDFs.

 

The options that you've chosen in "SubProvType" will stay selected and will change only when the user manually selects another option in the "Select" dropdown menu.

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 ,
Aug 22, 2020 Aug 22, 2020

Copy link to clipboard

Copied

LATEST

Or just move the original code to the field's Validation script, instead of Calculation...

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