Skip to main content
Participating Frequently
May 12, 2020
Answered

Accumulate multiple drop down list selections (with custom text) into one text field in a form

  • May 12, 2020
  • 2 replies
  • 2834 views

I have 7 dropdown lists with custom text. I would like to some how populate the selections from these drop down lists (with the custom text) into a single text field in a list format. However would it be possible to exclude certain drop down list selections from being populated into the text field. 

Each drop down list has the following slections:

" ", "N/A", "C1", "C2", "C3"

When either "C1", "C2", "C3" are selected. I would like this to be copied into the text field along with the custom text.

When either " " or "N/A" are selected. I would like these not to be populated into the text field.

My Javascript knowledge is very limited so any info would be greatly appreciated.

This topic has been closed for replies.
Correct answer try67

Unfortunately I'm not allowed to share the original form I intended to use this script on. However I have created a simplified version with 7 drop-down fields and a text field to test the code. Hopefully this will be enough. I have attached it to the original message.


Change this line:

for (var i=0; i<=7; i++) {

To:

for (var i=0; i<7; i++) {

2 replies

try67
Community Expert
Community Expert
May 13, 2020

Use this code as the custom calculation script of the text field where you want to show all the values:

 

var values = [];
var a = "a".charCodeAt(0);
for (var i=a; i<=7; i++) {
	var f = this.getField("DropDown7"+String.fromCharCode(i));
	var v = f.valueAsString;
	if (v!=" " && v!="N/A") values.push(v);
}
event.value = values.join("\n");
SullinetAuthor
Participating Frequently
May 13, 2020

Thanks for the code. I've tested it out on my form and the text field doesn't seem to be populating with the drop-down field selections. Javascript debugger did pop up, but I couldn't make heads or tails of it. I've attached a screen shot if you wouldn't mind taking a look.

 

try67
Community Expert
Community Expert
May 13, 2020

It looks like you're running it in debug mode.

Go to Edit - Prefs. - JavaScript and tick off "Enable JavaScript Debugger" and then restart the application and try again.

try67
Community Expert
Community Expert
May 12, 2020

Where is the "custom text" coming from, exactly?

SullinetAuthor
Participating Frequently
May 13, 2020

The custom text would be manually typed in each time, as sort of a brief description. 

For example I select "C3" from the drop down list and then type in more details in the same box. So it might end up being "C3 - missing schedule"

try67
Community Expert
Community Expert
May 13, 2020

OK... And what are the names of the drop-down fields?