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

Combine multiple text fields

alex_kahndesign
Registered: Feb 14 2011
Posts: 7

Hi there,
 
Wondering if someone could help as I am quite new to this. I am currently creating a spec sheet of a new vehicle for the company, what I am trying to achieve is to create a summary page showing all the additional extras that the customer has ticked to add to their vehicle.
 
A quick example that I have achieved so far:
 
Wheels [ ]
Side Vents [ ]
Exhaust Tip [ ]
Interior [ ]
 
You tick all 4 boxes, it will show a summary of:
 
Wheels
Side Vents
Exhaust Tip
Interior
 
The summary section is achieved by following script:
 
event.value = this.getField("Text308").value + "\n" + this.getField("Text309").value + "\n" + this.getField("Text310").value + "\n" + this.getField("Text311").value;
 
The problem comes when say the customer only ticked Interior, the summary section will then show:
 
(empty line)
(empty line)
(empty line)
Interior
 
How do I get it so that the extras that not ticked are ignored and Interior will come up to the top.
 
Many thanks in advance.
 
Kind regards,
 
Alex
 

My Product Information:
Acrobat Pro 9.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Use something like this:
if (this.getField("Text308").isBoxChecked(0)) event.value+=this.getField("Text308").value+"\n";
etc for the other fields.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

alex_kahndesign
Registered: Feb 14 2011
Posts: 7
hi try67

Thanks for your reply. Pasted your script into the editor but nothing is showing up. Have I done something wrong? What is BoxChecked(0)?

Many thanks.

Kind regards,

Alex
try67
Expert
Registered: Oct 30 2008
Posts: 2398
isBoxChecked (not BoxChecked) returns 1 if the field is checked, and 0 if not. The code should have been:

if (this.getField("Text308").isBoxChecked(0)==1) event.value+=this.getField("Text308").value+"\n";

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

alex_kahndesign
Registered: Feb 14 2011
Posts: 7
Thanks again,

it still not returning any results.

Should BoxChecked be related to anything?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Again, it's not BoxChecked but isBoxChecked. If you're not using the right name, it won't work.
And it's related to the field that calls it (Text308) in my example.
Do you see any errors in the console?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

alex_kahndesign
Registered: Feb 14 2011
Posts: 7
Yes Sorry, I was using the right name, just pasting it here incorrectly.

no error shown in the console as far as I can see.


gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
I would use the following document level scripts to build the final display string and force a 'Off' value to null:

// function can be placed in the fields custom calculation script or as a document level script.
function fillin(s1, s2, s3, sep) {
var test = 0;
s1 = s1.toString();
s2 = s2.toString();
s3 = s3.toString();

// figure which parameters to process based on logical bit values
if (s1 != "") { // set 1 bit
test |= 1;
}
if (s2 != "") { // set 2 bit
test |= 2;
}
if (s3 != "") { // set 4 bit
test |= 4;
}

// process parameters based on above action
if (test == 0) { // no passed parameters - 000
return "";
}
if (test == 1) { // only s1 - 001
return s1;
}
if (test == 2) { // only s2 - 010
return s2;
}
if (test == 3) { // s1 and s2 - 011
return s1 + sep + s2;
}
if (test == 4) { // only s3 - 100
return s3;
}
if (test == 5) { // s1 and s3 - 101
return s1 + sep + s3;
}
if (test == 6) { // s2 and s3 - 110
return s2 + sep + s3;
}
if (test == 7) { // all three - 111
return s1 + sep + s2 + sep + s3;
}
}

function Off2Null(sValue) {
// force an Off value to Null string
return sValue == "Off"? "" : sValue;
}

Then one can use a custom calculation script like:

// get value of wheels
var sWheels = this.getField('Wheels').value;
// adjust for "Off" value
sWheels = Off2Null(sWheels);

// get value of side vents or null
sSide = Off2Null(this.getField("Side Vents").value);

// get value of Exhaust tips or null
sExhaust = Off2Null(this.getField("Exhaust Tips").value);

// get value of interior or null
sInterior = Off2Null(this.getField("Interior").value);

sOption = fillin(sWheels, sSide, sExhaust, "\n");
event.value = fillin(sOption, sInterior, "", "\n");

Fill In Example

George Kaiser

alex_kahndesign
Registered: Feb 14 2011
Posts: 7
Fantastic!

Works like a treat, many thanks guys.

Kind regards,

Alex
alex_kahndesign
Registered: Feb 14 2011
Posts: 7
George,

would you be able to explain how the last 2 lines work?

sOption = fillin(sWheels, sSide, sExhaust, "\n");
event.value = fillin(sOption, sInterior, "", "\n");

the above is just an example, the list will actually be much much longer so it will be good if I can understand the last 2 lines so I can transfer it onto the real version.

Many thanks.

Alex
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
The document level script test the 3 passed strings for a non-null value and build a binary value that indicates which of the 3 passed parameters is not a null value. The script then tests that binary value and selects the appreciate action to join the strings. With 3 strings there are 8 possible combinations. Each parameter represents a binary bit position. S1 is the 1 position, S2 is the 2's position, S3 is the 4's position. If a parameter is passed the appropriate binary bit for that position is logically "OR"ed to the binary test value. After all of the 3 string parameters are tested, the value of binary test value has the binary bits set to which parameters were non-null and which were null. One then only needs to test the binary to know which string parameters are present. Read the comments for the 'case' statement. If S1 is present then the ones bit will be 1 (1, 3, 5, and 7). If S2 is passed then the 2nd bit (2's) will be 1 (2, 3, 6, and 7). If S3 is passed then the 3rd bit (4 binary) will be 1 (4, 5, 6, and 7). And if none are selected all of the bit will be zero or zero.

The fillin function can only process at most 3 parameters at time, so one may need to call it several times when there are more than 3 fields and pass 3 values to each time the function is called. When the number of fields to be passed is less than 3, then the missing string parameters need to be a null string. To add more text the building string, one passes the current value of the string to the fillin funciton along with 2 other string values.

George Kaiser

alex_kahndesign
Registered: Feb 14 2011
Posts: 7
Hi George,

Thank you so much for your help.

If we have more than 3 options, or 69, how would I change the script to make it work?

Many thanks again.

Kind regards,

Alex
ccastiglio
Registered: Jan 13 2009
Posts: 3
Hello--I am also new to this--i am trying to create electronic letterhead with a blank second page. The first page has a large text field to accommodate the body of the letter. The second page also has a large text field to accommodate what will not fit on the first page. I want the overflow from the body of the letter on the first page to automatically flow to the second page field. Can you help me ? thanks cara

cara