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

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

Community Beginner ,
May 12, 2020 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

1.5K

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 , May 14, 2020 May 14, 2020

Change this line:

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

To:

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

Votes

Translate

Translate
Community Expert ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

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

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 ,
May 13, 2020 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"

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 ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

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

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 ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

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

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 ,
May 13, 2020 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?

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 ,
May 13, 2020 May 13, 2020

Copy link to clipboard

Copied

Each value to be on a new line 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 ,
May 13, 2020 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");

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 ,
May 13, 2020 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

 

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 ,
May 13, 2020 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.

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 ,
May 13, 2020 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");

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
May 14, 2020 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?

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 ,
May 14, 2020 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.

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 ,
May 14, 2020 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.

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 ,
May 14, 2020 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++) {

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 ,
May 14, 2020 May 14, 2020

Copy link to clipboard

Copied

Just tested it and it's working perfectly. Thanks very much for all your 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 ,
May 14, 2020 May 14, 2020

Copy link to clipboard

Copied

Thanks for the correction, Thom!

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 ,
May 14, 2020 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.

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 ,
May 14, 2020 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.

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 ,
May 14, 2020 May 14, 2020

Copy link to clipboard

Copied

LATEST

That works great. Thanks again!

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