Expand my Community achievements bar.

textfield :post code change dropdowlist :town


Former Community Member

On the first two numbers entered by the user in the textfield:postcode i want to change the default value of a dropdownlist:town automatically.

Thanks for your help !
1 Reply


Former Community Member
This is certainly possible but unfortunately not that easy to do since you have to use some script and you need to know how to get the text and value associated to items in a list (List Box or Drop Down List object).

While the XFA Scripting Object Model gives you functions to add, clear and retrieve bound items to/from a list object, it doesn't give you a function that lists the items in text/value pairs (because items in a list are either simply text or text/value pairs depending on whether you specified values for the items in the list or not).

Unfortunately, retrieving the items in a list isn't a trivial task because you need to know the underlying XFA that's used to define the "text" and "value" values that represent items in the list: Depending on whether a list has specified values, one or two <items> tags are used.

In order to spare you the trouble of figuring this out, I thought I would throw-together a little sample which has script in a script object to retrieve the text/value item pairs from a list and automatically select the one that's the closest match to what the user is starting to type in a text field which captures a postal code (at least, this is what I understood you were trying to do based on your question). I put lots of comments in the script object functions so that you can understand what's going on.

The key is to retrieve the items in the list and then compare their values to what the user is currently entering into the text field by using the text field's Change event. Of course, the execution could be optimized by caching the List Item Array in a form variable instead of retrieving it on every change to the text field but since the list only contains 4 items, it's not an expensive operation (yet).

Finally, it's important to note that the comparison between the value entered into the postal code text field and the values in the list is case-sensitive so entering "k1" will not result in a selection change in the list while "K1" will.

Let me know if you have any questions.


Adobe Systems