Populate Text Field Based On Drop-Down List Selection | Community
Skip to main content
June 12, 2006

Populate Text Field Based On Drop-Down List Selection

  • June 12, 2006
  • 22 replies
  • 81492 views
I'm trying to set up a form so that a text field will populate with default text (that could later be edited by the end user) based on a users previous drop-down selection.



For example:



The end user is putting together a proposal for a client and is able to choose the type of proposal or service from a drop-down list. Once the user makes a selection from the drop-down list a text field is populated with default text describing the service.



The only catch is that the end user would need to be able to edit the default text. An example would be if an individual purchased a car but all the specific features and/or accessories could be added into the default text as necessary based on the purchasers desired upgrades. The common or universal features of the car would, however, show up as the default text.



Would this scenario be possible through the use of XML? Any tips on how I can accomplish this would be much appreciated.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

22 replies

June 21, 2006
Thanks so much Stefan! You were right on target and it works like a charm.
June 20, 2006
I'm finding it a little difficult to grasp what you're trying to accomplish so here's what I think you're asking for: You have a form which has a drop down list and a text field. When the user selects an item in the drop down list, you would like the text field to be automatically populated with an initial (default) value describing the selected item which the user could then edit (in the text field) to suit their specific needs.



If that's correct, then you would need just a little bit of script on the drop down list's Change event which would determine the item selected by the user and would set the text field's value to that which pertains to the new selection.



Let's say the text field is named "TextField1" and that you've associated a value to each item in the drop down list so that the selection is easy to compare in order to determine which initial (default) value to set in the text field. In your drop down list's Change event, you could use the following script (in JavaScript):



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



switch (sNewSel)

{

case "1": // car purchase

TextField1.rawValue = "Basic features:\n- frame\n- wheels\n- glass";

break;



case "2": // other purchase

TextField1.rawValue = "Basic features..."

break;



default: // unknown value -- do nothing

break;

}




Here we see the use of the
xfa.event.newText property in order to retrieve the text associated to the item which was just selected in the drop down list. Then we use the
boundItem method of the drop down list (this) in order to retrieve the value that we associated to that item. Finally, we check the value and assign multi-lined values (note the "\n" characters in the strings which represent new lines) to our multi-lined TextField1 field's value.



To help illustrate this, I've create a small sample form which uses the code I described above with the added feature that the text field is disabled until the user makes a selection in the drop down list.



Stefan

Adobe Systems
June 1, 2010

Hello Stefan,

I'm interested in the sample file you've created. Could you post it again?   I am also trying to populate textfields which are on different pages than the drop down lists, and have not succeeded. Can you help? Thanks.

thanks.

Nellie