How to populate multiple text boxes from one dropdown selection

Dec 08, 2020

Copy link to clipboard

Copied

Hi there

I am trying to populate two text boxes on a form triggered by one selection from a dropdown list.

Each dropdown selection has two attributes that I want to display, with one of them able to be overwritten.

My knowledge is limited but I have managed to get it to work for one attribute running this script on the 'Colour' dropdown Mouse up trigger:-

 

this.getField("Colour").setItems(new Array(

["",""],

["Black","1995"],

["White","1993"],

["Grey","1998"]

));

 

And adding this custom calculation script to the 'Year' text box:-

event.value=this.getField("Colour").value

(This variable is fixed and can’t be changed by the user).

 

I'd like to populate a second text box ‘Percentage’, with a colour attribute value (0.75%, 0.50%, 0.00% respectively), that could be overwritten by the user.

I thought I could just extend the array to cover a third variable but I can't make that work.

Can anyone guide me with how to do this?

Many thanks

 

 

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

20

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

How to populate multiple text boxes from one dropdown selection

Dec 08, 2020

Copy link to clipboard

Copied

Hi there

I am trying to populate two text boxes on a form triggered by one selection from a dropdown list.

Each dropdown selection has two attributes that I want to display, with one of them able to be overwritten.

My knowledge is limited but I have managed to get it to work for one attribute running this script on the 'Colour' dropdown Mouse up trigger:-

 

this.getField("Colour").setItems(new Array(

["",""],

["Black","1995"],

["White","1993"],

["Grey","1998"]

));

 

And adding this custom calculation script to the 'Year' text box:-

event.value=this.getField("Colour").value

(This variable is fixed and can’t be changed by the user).

 

I'd like to populate a second text box ‘Percentage’, with a colour attribute value (0.75%, 0.50%, 0.00% respectively), that could be overwritten by the user.

I thought I could just extend the array to cover a third variable but I can't make that work.

Can anyone guide me with how to do this?

Many thanks

 

 

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

21

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
Dec 08, 2020 0
try67 LATEST
Most Valuable Participant ,
Dec 08, 2020

Copy link to clipboard

Copied

You can put multiple values in the second variable, separated by a known delimiter (such as "~" or ";") and then use the split method to split that single string into an array of strings, and apply each part to a different field.

 

If you're interested, I've created a (paid-for) tool that allows you to set up such a field much more easily, without having to write any code. See: http://try67.blogspot.com/2015/07/acrobat-populate-fields-from-dropdown.html

You can also get it from my new web-site, where's there's currently a "soft launch" sale (The discount code is available on the front-page):
https://www.try67.com/tool/acrobat-populate-fields-from-dropdown

 

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...
Dec 08, 2020 0