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

New Here ,
May 12, 2020

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript

Views

436

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

1 Correct Answer

Most Valuable Participant , May 14, 2020
try67 Most Valuable Participant , May 14, 2020
Change this line: for (var i=0; i<=7; i++) { To: for (var i=0; i<7; i++) {

Likes

Translate

Translate
Jump to answer Jump to answer
Most Valuable Participant ,
May 12, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sullinet AUTHOR
New Here ,
May 13, 2020

Copy link to clipboard

Copied

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"

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
May 13, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sullinet AUTHOR
New Here ,
May 13, 2020

Copy link to clipboard

Copied

"DropDown7a", "DropDown7b", "DropDown7c", "DropDown7d", "DropDown7e", "DropDown7f", "DropDown7g"

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
May 13, 2020

Copy link to clipboard

Copied

And how do you want to concatenate the values? Should each one be on a new line (if it's a multi-line field), or separated by a comma, or a space?

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sullinet AUTHOR
New Here ,
May 13, 2020

Copy link to clipboard

Copied

Each value to be on a new line please.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
May 13, 2020

Copy link to clipboard

Copied

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");

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sullinet AUTHOR
New Here ,
May 13, 2020

Copy link to clipboard

Copied

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.debugger.jpg

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
May 13, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
May 13, 2020

Copy link to clipboard

Copied

Code Correction:

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

 

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sullinet AUTHOR
New Here ,
May 14, 2020

Copy link to clipboard

Copied

Have now ticked off the debugger, restarted and have inserted the new code. Still no joy though. Any ideas?

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
May 14, 2020

Copy link to clipboard

Copied

Can you share the actual file with us?

You can attach it to the original message using the tiny paperclip icon at the bottom when you edit it, or upload it to a file-sharing website (like Dropbox, Google Drive, Adobe Cloud, etc.), generate a share link and then post it here.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sullinet AUTHOR
New Here ,
May 14, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
May 14, 2020

Copy link to clipboard

Copied

Change this line:

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

To:

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

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sullinet AUTHOR
New Here ,
May 14, 2020

Copy link to clipboard

Copied

Just tested it and it's working perfectly. Thanks very much for all your help.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
May 14, 2020

Copy link to clipboard

Copied

Thanks for the correction, Thom!

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sullinet AUTHOR
New Here ,
May 14, 2020

Copy link to clipboard

Copied

Sorry to be a pest. Is it possible to alter this script to combine 31 drop-down fields  with exactly the same values instead?

The names of the drop-down fields are "Result1", "Result2" etc. up to 31.

I attempted to try and alter the code myself, but with no luck.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
May 14, 2020

Copy link to clipboard

Copied

Yes, in fact, with those names it's easier. Try this:

 

var values = [];
for (var i=1; i<=31; i++) {
	var f = this.getField("Result"+i);
	var v = f.valueAsString;
	if (v!=" " && v!="N/A") values.push(v);
}
event.value = values.join("\n");

 

If it's not working open the JS Console (Ctrl+J) and check for error messages.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sullinet AUTHOR LATEST
New Here ,
May 14, 2020

Copy link to clipboard

Copied

That works great. Thanks again!

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more