Highlighted

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

New Here ,
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, Create PDFs, PDF forms

Views

41

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

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

New Here ,
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, Create PDFs, PDF forms

Views

42

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
Adobe Community Professional ,
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.

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
Reply
Loading...
Adobe Community Professional ,
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.

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
Reply
Loading...
try67 LATEST
Most Valuable Participant ,
Aug 22, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF