These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Combining entries from multiple fields into one.

craigatlantic
Registered: Nov 4 2009
Posts: 13

Hello,

If I had a PDF with 3 drop-down boxes, that the user would select from, could the selections be combined into one text field? Perhaps have each item seperated by a comma and space ", " ?

The end result could look like:

"LARGE, SHORT SLEEVE, BLUE"

...But all 3 items would come from 3 seperate drop down menus named "size", "type" and "color"

Could anyone help me with the JavaScript please?

I appreciate it!

Craig

My Product Information:
Acrobat Pro 9.2, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
In Acrobat you can use the '+' operator to concatenate values. But for combining multiple fields you may want to use a document level function to allow for the inserting to separators and adjusting for missing data.

// document level function// Concatenate 3 strings with separators where neededfunction fillin(s1, s2, s3, sep) { /*Purpose: concatenate up to 3 strings with an optional separator

 inputs:

s1: required input string text or empty string

s2: required input string text or empty string

s3: required input string text or empty string

sep: optional separator sting

 returns:

sResult concatenated string

*/
 // variable to determine how to concatenate the stringsvar test = 0; // all strings nullvar sResult; // re slut string to return // force any number string to a character string for input variabless1 = s1.toString();s2 = s2.toString();s3 = s3.toString();if(sep.toString() == undefined) sep = ''; // if sep is undefined force to null /*assign a binary value for each string present

so the computed value of the strings will indicate which strings are present

when converted to a binary value

*/
if (s1 != "") test += 1; // string 1 present add binary value: 001if (s2 != "") test += 2; // string 2 present add binary value: 010if (s3 != "") test += 4; // string 3 present add binary value: 100 /* return appropriate string combination based oncalculated test value as a binary value

*/
switch (test.toString(2)) { case "0": // no non-empty strings passed - binary 0sResult = "";break; case "1": // only string 1 present - binary 1sResult = s1;break; case "10": // only string 2 present - binary 10sResult = s2;break; case "11": // string 1 and 2 present - binary 10 + 1sResult = s1 + sep + s2;break; case "100": // only string 3 present - binary 100sResult = s3;break; case "101": // string 1 and 3 - binary 100 + 001sResult = s1 + sep + s3;break; case "110": // string 2 and 3 - binary 100 + 010sResult = s2 + sep + s3;break; case "111": // all 3 strings - binary 100 + 010 + 001sResult = s1 + sep + s2 + sep + s3;break; default: // any missed combinationssResult = "";break;} return sResult;}

// custom calculation scriptvar sSize = this.getField('size').value;var sType = this.getField('type').value;var sColor = this.getField('color').value;event.value = fillin(sSize, sType, sColor, ', ');

George Kaiser