Populate Text Field Based On Drop-Down List Selection

5,777 views
Skip to first unread message

Katarzyna McMahon

unread,
Oct 25, 2011, 12:30:26 PM10/25/11
to Adobe LiveCycle Developers
Hello!
I have finally found some javascrpt that could create the effect I am
looking for in my PDF form. I am looking to create a drop-down menu
that is populated by a list of University courses. If a person selects
a course from the dropdown menu, a course description will appear in a
text box underneath the dropdown menu. I do not know javascript, so I
have been searching for code that I can simple "copy and Paste" into
the correct events and alter with my own text. Many of the forums
posted the following code that I could not get to work:

http://forums.adobe.com/message/1334823
http://www.webmasterworld.com/javascript/3865662.htm

I have since found some code that makes a subform appear when a person
selects an item from the dropdown menu. I can make that programming
work, but the subforms will not layer on top of eachother. So I would
have to have each course description appear successively lower on a
page.
But this is the only code that has worked for me so far:
http://blogs.adobe.com/samartha/2010/11/tutorial-article-on-designing-interactive-pdf-forms.html
There is a url that connects to an example pdf in response to Hadray's
question half way down the page.

Does any one know why the code in the first two urls does nothing? I
am pretty new to LiveCycle. I am working with LiveCycle ES 8.2. If you
are able to create an example PDF I would appreciate it it very much!

Jono Moore

unread,
Oct 31, 2011, 12:32:26 PM10/31/11
to live...@googlegroups.com
On 25 October 2011 09:30, Katarzyna McMahon <kasia....@gmail.com> wrote:
Hello!
I have finally found some javascrpt that could create the effect I am
looking for in my PDF form. I am looking to create a drop-down menu
that is populated by a list of University courses. If a person selects
a course from the dropdown menu, a course description will appear in a
text box underneath the dropdown menu. I do not know javascript, so I
have been searching for code that I can simple "copy and Paste" into
the correct events and alter with my own text. Many of the forums
posted the following code that I could not get to work:

http://forums.adobe.com/message/1334823
http://www.webmasterworld.com/javascript/3865662.htm

Did you get this figured out?

The code from the first link is the one you want. The second link is for web-based JavaScript.

You need to put the code on the Change event of your dropdown list. And you want to set the Binding of the dropdown list to "Specify Item Values" on the Binding tab of the Object palette - then each of your list items will be assigned a number for use in the script.

In the script you need to add a separate "case" statement for each choice in the dropdown list - the case number corresponding to the value of the selection. And then put the text for the selection inside the quotation marks after the equals sign. The "\n" in the text is for adding a new line.

var selection = this.boundItem(xfa.event.newText);

switch (selection)
{
  case "1": // Selection 1
    TextField1.rawValue = "Math 101:\nThis course is for...";

    break;
  case "2": // Selection 2
    TextField1.rawValue = "Math 102..."
    break;
}

In the script above you'll want to change "TextField1" to the name of the text box you want the text to show up in. 
Reply all
Reply to author
Forward
0 new messages