Copy link to clipboard
Copied
I have a table of 14x15 rows and columns in Adobe PDF form, and I have to add JavaScript to all the fields/cells. I need to add code in each field separately. Is there a way to add the code all at once?
Copy link to clipboard
Copied
Yes, you can use script to loop through fields and use setAction to put code into fields.
Copy link to clipboard
Copied
Yes, you can use script to loop through fields and use setAction to put code into fields.
Copy link to clipboard
Copied
Thank you for the guidance. It works.
Copy link to clipboard
Copied
The same script at any field?
Copy link to clipboard
Copied
No, I have different codes for each row and column, but each column has a same incremental code. What I did is, I prepared codes for each column separately, and pasted in a button action as "Mouse up". Here is an example for one column.
// Code for adding Different JavaScript to Multiple Rows
for ( var i = 2; i < 16; i++)
{
var code = "";
code += "var len = event.target.value.toString().length;";
code += "\n" + "if (len<8) {";
code += "\n" + " event.target.textSize = 10;";
code += "\n" + "}";
code += "\n" + "else if (len>7) {";
code += "\n" + " event.target.textSize = 9;";
code += "\n" + "}";
code += "\n" + "if (len>10) {";
code += "\n" + " event.target.textSize = 8;";
code += "\n" + "}";
code += "\n" + "if (len>12) {";
code += "\n" + " event.target.textSize = 7;";
code += "\n" + "}";
code += "\n" + "if (len>14) {";
code += "\n" + " event.target.textSize = 6;";
code += "\n" + "}";
code += "\n" + "//////////////////////////////////////////////";
code += "\n" + "var c = this.getField(\"Pier IDRow" +i+ "\").valueAsString;";
code += "\n" + "var v = this.getField(\"Soil Type at Pier BaseRow1\").valueAsString;";
code += "\n" + "if (c==\"\") event.value = \"\";";
code += "\n" + "else event.value = v;";
code += "\n" + "";
var rname = "Soil Type at Pier BaseRow"+i;
this.getField(rname).setAction("Calculate", code);
this.calculateNow();
}
Copy link to clipboard
Copied
When you use document level functions it is easier to change and debug the code.

