• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Populate fields based on Drop Down List Selection

Community Beginner ,
May 25, 2020 May 25, 2020

Copy link to clipboard

Copied

I'm trying to set up a form so that four text fields will populate with data from a previously user entered field (separate text in each text field) at the same time.

 

Below is a screenshot of the fields that I am looking to populate when "Sole-Trader" is selected from the "employment_type1" dropdown list:

Annotation 2020-05-26 152759.jpg

 

When the dropdown list is set to "Sole-Trader", the data for fields "undefined_68, 70, 72 & 74" is to come from the following fields, which have been completed earlier in the document.

Annotation 2020-05-26 153301.jpg

 

I have reviewed the existing threads and can find the following script, which I have attempted to modify, but to no avail:

 

var v1 = this.getField("employment_type1").valueAsString;

if (v1=="Sole-Trader") undefined_66 = ("residential_address_1");

else event.value = "";

 

 

Any guidance would be greatly appreciated.

TOPICS
Acrobat SDK and JavaScript

Views

2.5K

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
community guidelines

correct answers 1 Correct answer

Community Expert , May 26, 2020 May 26, 2020

You can use this code as the custom Validation script of the drop-down field:

 

if (event.value=="Sole Trader") {
	this.getField("undefined_66").value = this.getField("residential_address_1").value;
	this.getField("undefined_66").readonly = true;
} else {
	this.getField("undefined_66").readonly = false;
}

 

Make sure to tick the option to commit the selected value immediately, under the field's Properties, Options tab.

Votes

Translate

Translate
Community Expert ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

To transfer values of fields use this:

this.getField("undefined_66").value = this.getField("residential_address_1").value;

Votes

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
community guidelines
Community Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Thank you for your response and the script you have provided, which does populate the "undefined_66" field with the previously entered data, however it is not contingent upon "Sole-Trader" being selected from the dropdown menu, which is a requirement of my document.

Votes

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
community guidelines
Community Expert ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

The main question is, do you want those fields to be editable by the user, when another option is selected in the drop-down?
If so, using their Calculation code is not a good idea. I would use the Validation event of the drop-down to copy the values, but that would mean that if they change the fields you're copying from after "Sole Trader" has been selected the values won't update in the second set of fields.

Votes

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
community guidelines
Community Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Hi Try67, 

 

Thanks for the response and yes, if the user initially selects "Sole-Trader" from the dropdown menu, I would like the "undefined_66" field to be automatically populated with the previously entered data in the "residential_address_1" field. 

 

If however, the user changes their mind and replaces "Sole-Trader" with another option, e.g. "PAYG", they need to be able to manually enter the details of their employer's address in the "undefined_66, 68, 70, 72 & 74" fields.

 

Any suggestions on what this script would look like?

 

Love your work btw.

Votes

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
community guidelines
Community Expert ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

You can use this code as the custom Validation script of the drop-down field:

 

if (event.value=="Sole Trader") {
	this.getField("undefined_66").value = this.getField("residential_address_1").value;
	this.getField("undefined_66").readonly = true;
} else {
	this.getField("undefined_66").readonly = false;
}

 

Make sure to tick the option to commit the selected value immediately, under the field's Properties, Options tab.

Votes

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
community guidelines
Community Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

"Make sure to tick the option to commit the selected value immediately, under the field's Properties, Options tab."  - Where exactly is this box you are referring to? As per the following screenshot, when I go to PROPERTIES > OPTIONS, there is no box which can be ticked to commit the selected value immedaiately.

 

Annotation 2020-05-26 235008.png

Votes

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
community guidelines
Community Expert ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Look at the drop-down field.

Votes

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
community guidelines
New Here ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

I am trying to build a form that will populate an address in a text feild when one of the 11 companies is selected from a dropdown list.  How do I do this?  Once the company is selected from the dropdown list, I want the address attached to that specific company to auto populate on the form.

Votes

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
community guidelines
Community Expert ,
Aug 20, 2020 Aug 20, 2020

Copy link to clipboard

Copied

LATEST

The code I posted above can do that, if adjusted to include the actual values in your file.

 

Or you can use this (paid-for) tool I've developed that allows you to set it up easily and quickly, without having to write any code: http://try67.blogspot.com/2015/07/acrobat-populate-fields-from-dropdown.html

Votes

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
community guidelines