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

Combine into 1?

Eikou
Registered: Feb 5 2009
Posts: 30

I have a textfield named T1
I have a textfield named T2
I have a textfield named T3

and I have a textfield named Summary

so when a user fills in T1 Green
T2 is not filled
so when a user fills in T3 Red

I need a script that ables in the Summary textfield whats is filled

the summary textfield should look like this:

Green
Red

you know to have a better overview what is filled in 1 textfield :)
any can help to create such script?

much tnx already!

My Product Information:
Acrobat Pro 9.0, Macintosh
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
For the specifid question:

//custom calculation script for T3:
this.getField('T3').value = ''; // clear field
var sT1 = this.getField('T1').valueAsString; // T1 as a string
// if T1 not empty
if(sT1 != '') {
var sT2 = this.getField('T2').valueAsString;
// if T2 not empty
if(sT2 != '') {
this.getField('T3').value = sT1 + '\n' + sT2;
} // end if sT2 not empty
} // end if sT1 not empty


A more generalized solution that can be expanded for more than 2 fields:


// document level funciton
function fillin(s1, s2, s3, sep) {
// Concatenate 3 strings with separators where needed

// convert passed strings to a string value
s1 = s1.toString();
s2 = s2.toString();
s3 = s3.toString();

// assign a numeric value for presence of a gien string(s)
var test = 0; // no passed strings
if (s1 != "") test += 1; // s1 has a value
if (s2 != "") test += 2; // s2 has a value
if (s3 != "") test += 4; // s3 has a value

// return appropriate combination based on passed strings
if (test == 0) return ""; // no stings passed
if (test == 1) return s1; // s1 only
if (test == 2) return s2; // s2 only
if (test == 3) return s1 + sep + s2; // s1 and s2
if (test == 4) return s3; // s3 only
if (test == 5) return s1 + sep + s3; // s1 and s3
if (test == 6) return s2 + sep + s3; // s2 and s3
if (test == 7) return s1 + sep + s2 + sep + s3; // s1, s2, and s3
}
// end document level function

//custom calculation script for T3:
this.getField('T3').value = ''; // clear field
this.getField('T3').value = ''; // clear field
var sT1 = this.getField('T1').valueAsString; // T1 as a string
var sT2 = this.getField('T2').valueAsString; // T2 as a string
// if T1 & T2 not empty
if (sT1 != '' & sT2 != '')
this.getField('T3').value = fillin(sT1, sT2, '', '\n'); // fill data with seperator

The above solution is for Acrobat Forms using Acrobat JavaScript and not for LiveCycle Designer forms.

George Kaiser