These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

how to show a text box based on what is selected from a dropdown list

kez82
Registered: Jan 7 2010
Posts: 7

Hi,

Does anyone know how to display a text box based on what item is selected from a drop down list. I am trying to create a quotation whereby when you select an item from a drop down list, the corresponding information on the item is displayed (contained in a text box).

Cheers,
kez82

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Look at this tutorial?
http://www.acrobatusers.com/tutorials/2007/js_list_combo_livecycle/

The example in this article fills a text box based on a drop down selection.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

StalnakerJ
Registered: Jun 28 2009
Posts: 8
Dear Thomp,

Do you know of an example that only fills a text box basd on ONE drop down selection? I have found several, but I really just need a simple example. If dropdown list = Friday, then text box will populate 8. Seems so simple, but I just cannot make it work.
Thank you in advance.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If the values to be displayed in the text box are unique for each entry in the list then make the value you want to put in the text box the export value of the list item. The code for handling this situation is explained in the article linked above. All you need to worry about is the change code in the second drop-down box.

Another very simple and limited way to do this is with an "if" statement in the change event of the dropdown:
if(xfa.event.newText == "Friday")MyTextField.rawValue = 8;else if(xfa.event.newText == "Monday")MyTextField.rawValue = 1;elseMyTextField.rawValue = 0;

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

StalnakerJ
Registered: Jun 28 2009
Posts: 8
Dear Thomp,

Ok, I am still new, and this is what I did, but I have one more issue.

I have one dropdown and one text box.
With this dropdown, I clicked on the Binding tab and said "Specify Item Values" (I added the values that I need, example "Birthday" equals 8 (meaning 8 hours), but the "PTO" value is "blank"
I then click on my text box(it is for "Hours absent from work"). I used "this.rawValue=F.P1.Table1.Row1[0].Cell1[0].rawValue" in the calculate event.

All that seems to work fine(when I choose an option with a value). BUT, I need for the user to be able to place a "2" for the text box if the selected "PTO" from the dropdown. Why? so the employee can record hours they were away from work. But, everytime I place a number it disappers.

I am lead to believe that I am using the "wrong" train of thought/functions. I tried your code above, which makes sense to me, but I could not get it to work.

Basically I would like the employee to select "Birthday" in the dropdown and have the text box populate "8". But when they pick "PTO" I want them to be able to "input" the number they wish in the text box. Seems SO simple. I finally gave up and decided to post again. I did view some of your videos (pretty good videos I may add), but they didn't seem to be what I needed.

Any thoughts? Thank you in advance.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
No it doesn't seem simple. You've created a conflicted situation. In one case you want the field to be automatically populated, and in another situation you want the field to be user entered. You need to find a solution that resolves the confict.

A calculation script is run everytime any field on the form is changed, and it automatically populates the field it is attached to. You cannot use this event and have the field user entered at the same time. You have to use the change event on the drop down to drive the process.

Just to get you into the swing, try entering this code into the [b]change[/b] event of the dropdown. Make sure it's set to "JavaScript" and that the relative path to the text field is correct.
  MyTextField.rawValue = xfa.event.change;
Once you have this working it is a small step to get the full functionality working.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script