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

How to auto populate PDF dropdown list selection based on the selection of another dropdown list

Community Beginner ,
Mar 01, 2021 Mar 01, 2021

Copy link to clipboard

Copied

I have three dropdown boxes (dropdown A, dropdown B, and dropdown C). How can I get the selection in one to pull information from another and populate in another? For example I have 20 name selections in dropdown A. I have two options in dropdown B which are "yes" or "no". And I have 15 name selctions in dropdown C.

This is what I'm trying to accomplish:

If a user selects "yes" from dropdown B, I would like it to automatically pull their name selection from dropdown A, and input it into dropdown C.  However, if the user selects "no" in dropdown B, they would be able to manually select from the 15 names in dropdown C. 

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript , PDF forms

Views

3.1K

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 , Mar 01, 2021 Mar 01, 2021

As the custom calculation script of dropdown C you can use the following code:

if (this.getField("B").valueAsString=="yes") event.value = this.getField("A").valueAsString;

Votes

Translate

Translate
Community Expert ,
Mar 01, 2021 Mar 01, 2021

Copy link to clipboard

Copied

As the custom calculation script of dropdown C you can use the following code:

if (this.getField("B").valueAsString=="yes") event.value = this.getField("A").valueAsString;

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 ,
Mar 01, 2021 Mar 01, 2021

Copy link to clipboard

Copied

Thank you so much! You've answered a lot of my questions over the years. I am using this page as a template. I've created a button that poultates a new page from this template and changes each field value so they aren't linked. Is there a way to add this scrip to the page since whenever I populate a new page those form fields will no longer be called "B" but will be B1, B2, B3, etc.

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 ,
Mar 01, 2021 Mar 01, 2021

Copy link to clipboard

Copied

Glad to hear it!

If the other fields are also named the same, then yes. Try this:

 

var fieldNumber = event.target.name.replace("C", "");
if (this.getField("B"+fieldNumber).valueAsString=="yes") event.value = this.getField("A"+fieldNumber).valueAsString;

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 ,
Mar 02, 2021 Mar 02, 2021

Copy link to clipboard

Copied

Thanks! Where would I add this script? The document script?

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 ,
Jun 11, 2024 Jun 11, 2024

Copy link to clipboard

Copied

Hello TRY67!

 

Firstly thank you for all the help you give out! I was wondering if it is possible to have a drop down box with various different fields to select from. What i am trying to do is when an option from the drop down is selected. I would like to populate multiple text boxes with information for each different drop down selection. I would like different text to be filled from different options from the drop down box. To save keep filling the same text in every time. I hope this makes sense? If not i can try to explain clearer. 

 

Thank you! 

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 ,
Jun 13, 2024 Jun 13, 2024

Copy link to clipboard

Copied

Sure. You can do it using something like this as the custom Validation script of the drop-down field:

 

if (event.value=="Option 1") {
	this.getField("Text1").value = "ABC";
	this.getField("Text2").value = "DEF";
	this.getField("Text3").value = "HIG";	
} else if (event.value=="Option 2") {
	this.getField("Text1").value = "XYZ";
	this.getField("Text2").value = "VVV";
	this.getField("Text3").value = "ZZZ";	
} else {
	this.getField("Text1").value = "";
	this.getField("Text2").value = "";
	this.getField("Text3").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 ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

Thank you for your response. The code works like a charm! My only question to you is if i want to add more than the first two options to select from the drop down. Do i just add in option 3

 

if (event.value=="Option 1") {
} else if (event.value=="Option 2") {
} else {event.value=="Option 3") {
 
Do i just carry on this pattern for as many options i would like to select from the drop down menu?
 
That is my only question. Apart from that i just want to say how helpful you are. So thank you!

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 ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

This is what i mean buddy. Something like this:
 
if (event.value=="CR") {
this.getField("Text1").value = "Weight";
this.getField("Text2").value = "DEF";
this.getField("Text3").value = "HIG";
} else if (event.value=="CR2") {
this.getField("Text1").value = "XYZ";
this.getField("Text2").value = "VVV";
this.getField("Text3").value = "ZZZ";
} else } else {event.value=="Option 3") {
this.getField("Text1").value = "";
this.getField("Text2").value = "";
this.getField("Text3").value = "";
}
 
i apologise for the silly questions i am new to coding. 

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 ,
Jun 21, 2024 Jun 21, 2024

Copy link to clipboard

Copied

Sorry i figured the above question out. I am now wondering if i can also enable when i select an option from the drop down if it can also trigger a tix box to tick please?

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 ,
Jun 21, 2024 Jun 21, 2024

Copy link to clipboard

Copied

Sure. You can use this code:

this.getField("CheckBox1").checkThisBox(0, true);

Or if you know the export value:

this.getField("CheckBox1").value = "Choice1";

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 ,
Jun 25, 2024 Jun 25, 2024

Copy link to clipboard

Copied

LATEST

Hello. Thank you for the help. The drop down code, and also the tick box code all worked like a charm. So thank you very much for the help as i have no clue how to code. 

 

I have one last question for you... i promise. I am wondering if you know if its possible to add an automation for a weight calculation?

What i am after is weight vs net weight. So i already have text 1,2 &3 on the drop down autmation options which aut populates.

Charlie303735890y2h_0-1719304027723.png

Text 3 which says KG71 is where the weight will be populated. I am wondering if i could add text 4 for example and somehow add code to display the net weight as well as the weight. I would somehow have to add code to the drop down to minus the weight and display the net weight. I hope this all makes sense. if not then feel free to let me know and i will provide more information.

 

Again thank you so much for all the help!

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 ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

Something like this:

if (event.value=="Option 1") {

} else if (event.value=="Option 2") {

} else if (event.value=="Option 3") {

} else {

}

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