Skip to main content
Participant
April 10, 2024
Answered

Populating Text Field with Multiple Dropdown Selections

  • April 10, 2024
  • 1 reply
  • 1475 views

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.

Correct answer Nesa Nurani

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

1 reply

try67
Community Expert
Community Expert
April 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 drop-down field.

 

[Edited: Code fixed]

plmaresAuthor
Participant
April 10, 2024

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?