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

Get fields using Javascript

Anonymous

I have 3 check boxes with the names "VT" "VNT" and "VBJ" and a text field called "Text1"

What i am trying to do achieve is that when you click on a check box, the text VT/VNT/VBJ appears in "Text1"

I can to this easily from a script I found (below) and enter it in the calculate tab in the text field "Text1"

event.value = this.getField("VT").value;
if (event.value == "Off") event.value = ''; // do not display "Off" or no radio button checked

This does the job BUT how do i get the text field "Text1" to include all the check boxes that are ticked such as "VT" and "VNT" so it displays in the text field"Text1" as VT VNT ?

My Product Information:
Acrobat Pro 9.1.1, Macintosh
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
You have to test each check box field and determine if it should be included in the display. Once you have the values that are not 'Off' you will have to figure out how to put the results together adjusting for the missing data.
 // get the values of the check boxes and convert 'Off' values to 'null'var sVT = this.getField('VT').value;var sVNT = this.getField('VNT').value;var sVBJ = this.getField('VBJ').value;if(sVT == 'Off') sVT = '';if(sVNT == 'Off') sVNT = '';if(sVBJ == 'Off') sVBJ = '';

There is a function call 'fillin' provided with Acrobat's sample forms for the PDF form that can join up to 3 fields using an optional separator and adjust for missing data.

You can use function to combine data values with or without a separator and adjust for missing values.
function fillin(s1, s2, s3, sep) {var test = 0; // binary number to determine how to combine parametersvar sResult = ''; // result of combination s1 = s1.toString();s2 = s2.toString();s3 = s3.toString(); // figure which parameters to process based on logical bit valuesif (s1 != "") { // set 1 bittest |= 1;}if (s2 != "") { // set 2 bittest |= 2;}if (s3 != "") { // set 4 bittest |= 4;}// process parameters based on above actionif (test == 0) { // no passed parameters - 000sResult = '';}if (test == 1) { // only s1 - 001sResult =  s1;}if (test == 2) { // only s2 - 010sResult = s2;}if (test == 3) { // s1 and s2 - 011sResult = s1 + sep + s2;}if (test == 4) { // only s3 - 100sResult = s3;}if (test == 5) { // s1 and s3 - 101sResult = s1 + sep + s3;}if (test == 6) { // s2 and s3 - 110sResult = s2 + sep + s3;}if (test == 7) { // all three - 111sResult = s1 + sep + s2 + sep + s3;}// return constructed string   return sResult;} // end document level function fillin

Assuming your export value for the check box is the same as the name of the field, your custom calculation script for the text field can be:
 // get the values of the check boxes and convert 'Off' values to 'null'var sVT = this.getField('VT').value;var sVNT = this.getField('VNT').value;var sVBJ = this.getField('VBJ').value;if(sVT == 'Off') sVT = '';if(sVNT == 'Off') sVNT = '';if(sVBJ == 'Off') sVBJ = '';// filling the value using the non-null itemsevent.value = fillin(sVT, sVNT, sVBJ, '/');

George Kaiser

smitchell15 (not verified)
Thanx gkaiseril for getting back to me so quickly.

I've tried entering the last code that you gave me since the export values ARE the same as the field name for all the check boxes like you said but it still didn't work i'm afraid. I did play around with code a bit and somehow got it to work. I saved it and went straight back to it and it gone!!! And for the life of me I can't get it working again! What did I do and what/how could I change it to work again?

Thanx again