make a field visible based on a selection in a drop-down list

Community Beginner ,
Oct 31, 2018

Copy link to clipboard

Copied

I have been asked to create a PDF where a user will select from multiple choices.  Each choice should display a text box with different information.  I'm new to programming (and to programming in Adobe).  I understand from poking around that I will use validation script coding for the drop-down list.  I've found an example, but it doesn't work and I've checked and rechecked the code with the same outcome.  Here's the example code:

this.getField(txtDescription").display = event.value=="Other" ? display.visible : display.hidden;

txtDescription is the text box that will display if "Other" is selected from the drop-down list. 

For my form, I need 3, or more, drop-down choices, each of which will display a corresponding, otherwise hidden, text box.

Any pointers will be greatly appreciated.  Any links to tutorials would also be greatly appreciated.

Thank you

TOPICS
Acrobat SDK and JavaScript, Windows

Views

218

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

make a field visible based on a selection in a drop-down list

Community Beginner ,
Oct 31, 2018

Copy link to clipboard

Copied

I have been asked to create a PDF where a user will select from multiple choices.  Each choice should display a text box with different information.  I'm new to programming (and to programming in Adobe).  I understand from poking around that I will use validation script coding for the drop-down list.  I've found an example, but it doesn't work and I've checked and rechecked the code with the same outcome.  Here's the example code:

this.getField(txtDescription").display = event.value=="Other" ? display.visible : display.hidden;

txtDescription is the text box that will display if "Other" is selected from the drop-down list. 

For my form, I need 3, or more, drop-down choices, each of which will display a corresponding, otherwise hidden, text box.

Any pointers will be greatly appreciated.  Any links to tutorials would also be greatly appreciated.

Thank you

TOPICS
Acrobat SDK and JavaScript, Windows

Views

219

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
Oct 31, 2018 0
Engaged ,
Nov 01, 2018

Copy link to clipboard

Copied

Can you tell what the values will be? So what are the drop down menu options?

Option 1: _________

Option 2: _________

Option 3: _________

Option 4: _________

What fields will be on if Option 1 is selected:

What fields will be on if Option 2 is selected:

What fields will be on if Option 3 is selected:

What fields will be on if Option 4 is selected:

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...
Nov 01, 2018 0
Community Beginner ,
Nov 01, 2018

Copy link to clipboard

Copied

Certainly. Thank you for responding!

There will be 6 choices of buildings in the drop down field:

Atkinson Theater

Atkinson Heritage Center

Community Learning Center

Hudiburg Chevrolet Center

Learning Resource Center

Professional Training Center

For each selection, a corresponding hidden text frame should be visible:

Atkinson Theater should have this information shown in the text field:

Theater, capacity 256

Atkinson Heritage Center should have this information shown in the text field:

Conference, capacity 36

Pony Barn Sm. Conf, capacity 48

Pony Barn Lg. Conf, capacity 100

Atkinson Ctr. Grounds, capacity N/A

Community Learning Center should have this information shown in the text field:

Theater, capacity 190

Classroom 102, capacity 30

Classroom 108, capacity 12

Computer Lab 112, capacity 22

Classroom 203, capacity 24

Classroom 205, capacity 21

Combination 203/205, capacity 45

Hudiburg Chevrolet Center should have this information shown in the text field:

Theater, capacity 1,400

Learning Resource Center should have this information shown in the text field:

102B (faculty/staff only), capacity 12

102G (faculty/staff only), capacity 6

103, capacity 6

105, capacity 10

150 (Café – after hours only), capacity 36

112A (Central Stair Lounge), capacity 8

231, capacity N/A

Professional Training Center should have this information shown in the text field:

114 Theater, capacity 95

108-111 (Quad), capacity 120

108/109, capacity 60

108/110, capacity 60

109/111, capacity 60

110/111, capacity 60

213, capacity 36

106, capacity 30

108, capacity 30

109, capacity 30

111, capacity 30

211, capacity 16

Lobby, Commons, Quad, capacity 120

I know this is a lot of information. If you can provide an example of coding for just two selections (smaller selections), then I can do the text/coding for the remaining. I created the code according to an online example, but it isn’t working.

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...
Nov 01, 2018 0
Engaged ,
Nov 01, 2018

Copy link to clipboard

Copied

Try this... Don't forget to plug in the name of your drop down menu as well as the text box to populate

var theValue = this.getField("DROP DOWN MENU NAME").value;

if (theValue == "Atkinson Theater") {

    this.getField("textBoxName").value = "Theater, capacity 256";

} else if (theValue == "Atkinson Heritage Center") {

    this.getField("textBoxName").value = "Conference, capacity 36" +

        "\nPony Barn Sm. Conf, capacity 48" +

        "\nPony Barn Lg. Conf, capacity 100" +

        "\nAtkinson Ctr. Grounds, capacity N/A";

} else if (theValue == "Community Learning Center") {

    this.getField("textBoxName").value = "Theater, capacity 190" +

        "\nClassroom 102, capacity 30" +

        "\nClassroom 108, capacity 12" +

        "\nComputer Lab 112, capacity 22" +

        "\nClassroom 203, capacity 24" +

        "\nClassroom 205, capacity 21" +

        "\nCombination 203/205, capacity 45";

} else if (theValue == "Hudiburg Chevrolet Center") {

    this.getField("textBoxName").value = " Theater, capacity 1,400";

} else if (theValue == "Learning Resource Center") {

    this.getField("textBoxName").value = "102B (faculty/staff only), capacity 12" +

        "\n102G (faculty/staff only), capacity 6" +

        "\n103, capacity 6" +

        "\n105, capacity 10" +

        "\n150 (Café – after hours only), capacity 36" +

        "\n112A (Central Stair Lounge), capacity 8" +

        "\n231, capacity N/A";

} else { // This will give you Professional Training Center

    this.getField("textBoxName").value = "114 Theater, capacity 95" +

    "\n108-111 (Quad), capacity 120" +

    "\n108/109, capacity 60" +

    "\n108/110, capacity 60" +

    "\n109/111, capacity 60" +

    "\n110/111, capacity 60" +

    "\n213, capacity 36" +

    "\n106, capacity 30" +

    "\n108, capacity 30" +

    "\n109, capacity 30" +

    "\n111, capacity 30" +

    "\n211, capacity 16" +

    "\nLobby, Commons, Quad, capacity 120";

}

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...
Nov 01, 2018 0
Community Beginner ,
Nov 01, 2018

Copy link to clipboard

Copied

Thank you,

I will work with this and hoping for good results. Being new to this, it is intimidating but interesting, nonetheless.

Appreciate your responses.

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...
Nov 01, 2018 1
Engaged ,
Nov 01, 2018

Copy link to clipboard

Copied

Happy to try to help. If you can upload a file I can test it more for you and add in comments to try to help teach/explain. I'm still fairly new myself but always trying to help and learn with the community.

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...
Nov 01, 2018 0
Engaged ,
Nov 01, 2018

Copy link to clipboard

Copied

Here is something you could work off of....

var theValue = this.getField("DROP DOWN MENU NAME").value;

if (theValue == "Option 1"){

    this.getField("FIELD TO DISPLAY").display = display.visible;

    this.getField("FIELD TO HIDE").display = display.hidden;

    }

else if (theValue == "Option 2"){

    this.getField("FIELD TO DISPLAY").display = display.visible;

    this.getField("FIELD TO HIDE").display = display.hidden;

    }

else if (theValue == "Option 3"){

    this.getField("FIELD TO DISPLAY").display = display.visible;

    this.getField("FIELD TO HIDE").display = display.hidden;

    }

else { // This will give you Option 4

    this.getField("FIELD TO DISPLAY").display = display.visible;

    this.getField("FIELD TO HIDE").display = 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...
Nov 01, 2018 0