• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Add JavaScript to Multiple Fields

Community Beginner ,
Jun 05, 2021 Jun 05, 2021

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?

TOPICS
How to , JavaScript , PDF forms

Views

1.1K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 05, 2021 Jun 05, 2021

Yes, you can use script to loop through fields and use setAction to put code into fields.

Likes

Translate

Translate
Community Expert ,
Jun 05, 2021 Jun 05, 2021

Copy link to clipboard

Copied

Yes, you can use script to loop through fields and use setAction to put code into fields.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 05, 2021 Jun 05, 2021

Copy link to clipboard

Copied

Thank you for the guidance. It works.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 05, 2021 Jun 05, 2021

Copy link to clipboard

Copied

The same script at any field?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 05, 2021 Jun 05, 2021

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();
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 05, 2021 Jun 05, 2021

Copy link to clipboard

Copied

LATEST

When you use document level functions it is easier to change and debug the code.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines