Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
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

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
2.4K
Translate
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++) {

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

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

Translate
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

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"

Translate
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

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

Translate
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

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

Translate
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

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?

Translate
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

Each value to be on a new line please.

Translate
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

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

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.jpgexpand image

 

Translate
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

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.

Translate
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

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

Translate
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

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

Translate
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

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.

Translate
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

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.

Translate
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

Change this line:

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

To:

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

Translate
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

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

Translate
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

Thanks for the correction, Thom!

Translate
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

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.

Translate
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

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.

Translate
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
LATEST

That works great. Thanks again!

Translate
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