Copy link to clipboard
Copied
Hi, I want to export checkboxes values to textfield if it's checked, I have this code but it only works for last checkbox what I'm missing? checkboxes are "c 1" to "c 5".
var cVal = "";
for (var i=1; i<=5; i++) {
cVal =(this.getField("c " + i).value);}
event.value = cVal;
Try this:
var cVal = 0;
for (var i=1; i<=5; i++) {
cV =this.getField("c " + i).value;
if (cV != "Off") cVal += cV; // <-- corrected
}
event.value = cVal;
Copy link to clipboard
Copied
You can try it like this:
var f = this.getField("c");
var cVal = f.getArray();
var v = 0;
for (var i=0; i< cVal.length; i++)
v +=cVal[i].value+" ";
event.value = v;
Copy link to clipboard
Copied
thanks for your help but that code doesn't do anything. I put it in my text field custom calculation script right?
Copy link to clipboard
Copied
I made a mistake. And yes run it as custom calculation script.
Here it is:
var f = getField("c");
var cVal = f.getArray();
var v = "";
for (i =0 ; i < cVal.length ; i++) v += (cVal[ i ].value+" ")
event.value = v;
I'm not sure if the way you have the checkbox fields like "c 1", "c 2", "c 3" with a space in between the letter c and then followed by a number will work (but I may be wrong).
The getArray() method in Acrobat will assume that a parent name for a field has a hierarchy of "children" fields.
Usually the children field names are prefixed with the parent name and suffixed after a period (or maybe another special character). For example: myFieldName.1, myFieldName.2, myFieldName.3
If you are going to use the array the way you have it , then you may need to consider using the "new Array()" method.
Copy link to clipboard
Copied
Again I'm not getting anything, my fields are named "c 1" with space, if I change them to "c.1" then I get this:
Copy link to clipboard
Copied
Try this:
var cVal = 0;
for (var i=1; i<=5; i++) {
cV =this.getField("c " + i).value;
if (cV != "Off") cVal += cV; // <-- corrected
}
event.value = cVal;
Copy link to clipboard
Copied
Hi Bernd, thx for helping but I'm getting this error.
SyntaxError: syntax error
5:Console:Exec
undefined
Copy link to clipboard
Copied
The error was a "," it must a ";".
Copy link to clipboard
Copied
use ";" not "," in this line
if (cV != "Off") cVal += cV,
Copy link to clipboard
Copied
That code worked now. Thank you both for help.
Copy link to clipboard
Copied
What a nice little piece of code... Thank you!
Very useful.