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

Populating Text Field with Multiple Dropdown Selections

Community Beginner ,
Apr 10, 2024 Apr 10, 2024

Copy link to clipboard

Copied

Hello,

 

I have a dropdown (Reasons) with multiple selections (Test1, Test2, Test3). I want to be able to select one option (Test1), have that value populate a text field (ReasonsList), return to a new line or have a comma, and then populate another value when I select another option (selecting Test2 after Test1 would give me "Test1, Test2" in the text field).

 

Is this possible? I've found some Javascript in other community posts, but I'm not able to get it to work for my case.

TOPICS
Create PDFs , Modern Acrobat , PDF , PDF forms

Views

419

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 2 Correct answers

Community Expert , Apr 10, 2024 Apr 10, 2024

As the custom Validation script of the drop-down enter the following code:

 

 

if (event.value) {
	var reasonsListField = this.getField("ReasonsList");
	if (reasonsListField.valueAsString=="") reasonsListField.value = event.value;
	else reasonsListField.value+=", " + event.value;
}

 

 

Make sure to tick the option to commit the selected value of the drop-down automatically if you want the text field's value to update as soon as you make a selection. Otherwise it will only work when you exit the

...

Votes

Translate

Translate
Community Expert , Apr 10, 2024 Apr 10, 2024

There is an error in last line: else reasonsListField.value+=", " + event.value;

Votes

Translate

Translate
Community Expert ,
Apr 10, 2024 Apr 10, 2024

Copy link to clipboard

Copied

As the custom Validation script of the drop-down enter the following code:

 

 

if (event.value) {
	var reasonsListField = this.getField("ReasonsList");
	if (reasonsListField.valueAsString=="") reasonsListField.value = event.value;
	else reasonsListField.value+=", " + event.value;
}

 

 

Make sure to tick the option to commit the selected value of the drop-down automatically if you want the text field's value to update as soon as you make a selection. Otherwise it will only work when you exit the drop-down field.

 

[Edited: Code fixed]

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 ,
Apr 10, 2024 Apr 10, 2024

Copy link to clipboard

Copied

Thank you for the quick response. This handles the first part where it throws the value into the text field. Is it possible then to add a line break or comma, followed by a second selection value if I were to then click on "Test2" in the dropdown?

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 ,
Apr 10, 2024 Apr 10, 2024

Copy link to clipboard

Copied

There is an error in last line: else reasonsListField.value+=", " + event.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 ,
Apr 10, 2024 Apr 10, 2024

Copy link to clipboard

Copied

Thank you both for the responses. It looks like it's doing what I need it to. \o/

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 ,
Apr 10, 2024 Apr 10, 2024

Copy link to clipboard

Copied

If you don't want to allow duplicates, here is a modified script:

 

if (event.value) {
var reasonsListField = this.getField("ReasonsList");
if (reasonsListField.valueAsString == "") {
reasonsListField.value = event.value;} 
else {
var currentValues = reasonsListField.value.split(", ");
if (currentValues.indexOf(event.value) == -1) {
reasonsListField.value += ", " + event.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 Expert ,
Apr 10, 2024 Apr 10, 2024

Copy link to clipboard

Copied

LATEST

Good catch! I fixed it now.

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