Dropdown list to view or hide other fields

Explorer ,
Sep 17, 2018

Copy link to clipboard

Copied

I wanna create a PDF form that has conditional Dropdown list. For example, dropdown list has values: X, Y & Z. If the user chooses “X” he will see a list of checklist different than when he chooses “Y” or “Z”.. so is this possible to do this using adobe pro DC with javascrips ??. thanks..

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Here's an example:

var fields1 = ["Field1", "Field2", "Field3"];

var fields2 = ["Field4", "Field5", "Field6"];

for (var i in fields1) this.getField(fields1).display = (event.value=="X") ? display.visible : display.hidden;

for (var i in fields2) this.getField(fields2).display = (event.value=="Y") ? display.visible : display.hidden;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

305

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

Dropdown list to view or hide other fields

Explorer ,
Sep 17, 2018

Copy link to clipboard

Copied

I wanna create a PDF form that has conditional Dropdown list. For example, dropdown list has values: X, Y & Z. If the user chooses “X” he will see a list of checklist different than when he chooses “Y” or “Z”.. so is this possible to do this using adobe pro DC with javascrips ??. thanks..

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Here's an example:

var fields1 = ["Field1", "Field2", "Field3"];

var fields2 = ["Field4", "Field5", "Field6"];

for (var i in fields1) this.getField(fields1).display = (event.value=="X") ? display.visible : display.hidden;

for (var i in fields2) this.getField(fields2).display = (event.value=="Y") ? display.visible : display.hidden;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

306

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
Sep 17, 2018 0
Most Valuable Participant ,
Sep 17, 2018

Copy link to clipboard

Copied

Do you want to show/hide another field, or do you want to set the items available in a field based on the selection?

Both are possible, but require different approaches.

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...
Sep 17, 2018 0
Explorer ,
Sep 17, 2018

Copy link to clipboard

Copied

hi, it will be like bellow.

if i select "X" in drop down, bellow that should visible 5 questions & check boxes to select. if i select "Y" in drop down, before 5 questions & check boxes need to disappear & need to visible different 6 questions & check boxes to select in same place. same way i have 5 different drop down selections so same 5 set of questions & check boxes available to hide or display. hope it's clear. thanks..

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...
Sep 17, 2018 0
Most Valuable Participant ,
Sep 17, 2018

Copy link to clipboard

Copied

OK. The generic code to do it would be something like this (as the custom validation script of the drop-down field):

if (event.value=="X") {

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

     this.getField("Field2").display = display.hidden;
} else if (event.value=="Y") {

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

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

}

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...
Sep 17, 2018 0
Explorer ,
Sep 17, 2018

Copy link to clipboard

Copied

hi, thanks for the code. there are lot of items have to add so is that possible to short this code ??

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...
Sep 17, 2018 0
Most Valuable Participant ,
Sep 17, 2018

Copy link to clipboard

Copied

It's possible to use an array with the names of the fields to show/hide.

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...
Sep 17, 2018 0
Explorer ,
Sep 17, 2018

Copy link to clipboard

Copied

can u pls give me some example code ??. thanks...

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...
Sep 17, 2018 0
Most Valuable Participant ,
Sep 17, 2018

Copy link to clipboard

Copied

Here's an example:

var fields1 = ["Field1", "Field2", "Field3"];

var fields2 = ["Field4", "Field5", "Field6"];

for (var i in fields1) this.getField(fields1).display = (event.value=="X") ? display.visible : display.hidden;

for (var i in fields2) this.getField(fields2).display = (event.value=="Y") ? display.visible : display.hidden;

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...
Sep 17, 2018 1