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.
1 Correct answer
Change this line:
for (var i=0; i<=7; i++) {
To:
for (var i=0; i<7; i++) {
Copy link to clipboard
Copied
Where is the "custom text" coming from, exactly?
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"
Copy link to clipboard
Copied
OK... And what are the names of the drop-down fields?
Copy link to clipboard
Copied
"DropDown7a", "DropDown7b", "DropDown7c", "DropDown7d", "DropDown7e", "DropDown7f", "DropDown7g"
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?
Copy link to clipboard
Copied
Each value to be on a new line please.
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");
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.
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.
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");
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Have now ticked off the debugger, restarted and have inserted the new code. Still no joy though. Any ideas?
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.
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.
Copy link to clipboard
Copied
Change this line:
for (var i=0; i<=7; i++) {
To:
for (var i=0; i<7; i++) {
Copy link to clipboard
Copied
Just tested it and it's working perfectly. Thanks very much for all your help.
Copy link to clipboard
Copied
Thanks for the correction, Thom!
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.
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.
Copy link to clipboard
Copied
That works great. Thanks again!

