Copy link to clipboard
Copied
I have a PDF form with 83 checkboxes labelled "Group1.Check Box1" through to "Group1.Check Box83". I need the export values of checkboxes that are selected to appear in a field labelled "Awards" as a list.
The Group1 prefix is used for a separate script to display a another field when any checkbox is selected.
I am using the following calculation script for the "Awards" field but cannot get the data to display.
event.value=
this.getField(“Group1.Check Box1”).value+”\r”+
this.getField(“Group1.Check Box2”).value+”\r”+
this.getField(“Group1.Check Box3”).value+”\r”+
(and so on through to 82)
this.getField(“Group1.Check Box83”).value+”\r”;
event.value=event.value.replace(/Off\r/g,””)
Can someone advise where I am going wrong here?
Copy link to clipboard
Copied
First, you should run this script from the console window, sans event.value, to figure out what is going wrong.
Here's a video tutorial on how to use the console window:The Acrobat JavaScript Console Window - YouTube
Next, since you've used group naming you should use it. It's much more accurate than generating target fields names on the fly. And a bad target name could easily be the error that is keeping your script from running. Here's a variation on GKaiseril's code.
var cValue; // variable for field value;
var aAwards = new Array(); // array for check box values not "Off";
var aFlds = this.getField("Group1").getArray();
for(var i = 0; i < aFlds.length; i++)
{
cValue = aFlds.value;
if(cValue != "Off")
{
aAwards.push(cValue);
} // end field value not "Off";
} // end i loop;
event.value = aAwards.join("\r");
Copy link to clipboard
Copied
Your quotation marks are the smart quotation marks and not the simple ones. Always use a text editor designed for coding and not a word processor.
Make sure you have selected the "Multi-line" option.
A shorter script can be achieved using an array and a loop.
var oField; // variable for field;
var cValue; // variable for field value;
var aAwards = new Array(); // array for check box values not "Off";
for(var i = 1; i < 84; i++)
{
cValue = this.getField("Group1.Check Box" + i).value;
if(cValue != "Off")
{
aAwards.push(cValue);
} // end field value not "Off";
} // end i loop;
event.value = aAwards.join("\r");
Copy link to clipboard
Copied
Thank you for your reply. I have copied the above into the custom calculation script on the "Awards" field, but still showing no data when checkboxes are selected.
Copy link to clipboard
Copied
First, you should run this script from the console window, sans event.value, to figure out what is going wrong.
Here's a video tutorial on how to use the console window:The Acrobat JavaScript Console Window - YouTube
Next, since you've used group naming you should use it. It's much more accurate than generating target fields names on the fly. And a bad target name could easily be the error that is keeping your script from running. Here's a variation on GKaiseril's code.
var cValue; // variable for field value;
var aAwards = new Array(); // array for check box values not "Off";
var aFlds = this.getField("Group1").getArray();
for(var i = 0; i < aFlds.length; i++)
{
cValue = aFlds.value;
if(cValue != "Off")
{
aAwards.push(cValue);
} // end field value not "Off";
} // end i loop;
event.value = aAwards.join("\r");
Copy link to clipboard
Copied
Thom, this script is now working for me, however it now affects another script that was working previously.
On my form, I have "Group.1Check Box 17", "Group1.Check Box 18", "Group1.Check Box 19" and "Group1.Check Box 20". If 20 is selected it activates all previous checkboxes back to 17. The same applies if 19 and 18 are selected. I am using the following script for this on "Group1.Check Box 20":
var fn = new Array();
fn = ["Group1.Check Box17", "Group1.Check Box18", "Group1.Check Box19"];
for (var i = 0; i < fn.length; i++) {
if (this.getField(fn).type == "checkbox") {
this.getField(fn).checkThisBox(0, true) ;
}
}
I am using the same script for "Group1.Check Box 19" (removing "Group1.Check Box 19" from the fn) and for "Group1.Check Box18" (removing 18 and 19).
Can you advise why the above scripts are no longer working in conjunction with the script you provided? If I remove your script from the "Awards" field, the scripts I mentioned above work fine.
Copy link to clipboard
Copied
In what way are the scripts not working?
Every time any field is changed it triggers the calculation event. So your loop is causing several to happen very quickly. It's possible this is causing the issue. I'd suggest turning calculations off for the duration of our checkbox scripts.
Use this line at the top of the script.:
this.calculate = false;
And use this at the bottom of the script
this.calculate = true;
this.calculateNow();
Also, you are declaring the array in "fn" twice. Use only this line
var fn = ["Group1.Check Box17", "Group1.Check Box18", "Group1.Check Box19"];
Copy link to clipboard
Copied
Thank you Thom. This has solved my problem.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more