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

Help With For Loop, Field Names

Participant ,
Jan 15, 2020 Jan 15, 2020

Copy link to clipboard

Copied

This is a stub from a project. My goal is to look through all the fields in the document, then put any of them whose name begins with "topPh" (they all end in numbers) into my array fields[]. I'm still researching how to decide which names conatin the substring for the if statement, but in the meantime I am testing using this:

     var fields = [];
     for (var i = 0; i < this.numFields; i++){
          var f = this.getField(this.getNthFieldName(i)).name;
          if(f = "topPh2") fields.push(f);
     }     //end of for loop
     app.alert(fields);

I expected it to put one value in fields[]: topPh2. It seems to be doing it many times. In fact, I crashed Acrobat through console doing something similar. This is what it puts out:

output.png

 

What am I doing wrong here?

TOPICS
Acrobat SDK and JavaScript

Views

308

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

Participant , Jan 15, 2020 Jan 15, 2020

*Sigh*

This was easy. '=' is not a logical operator.... I needed '==':

     var fields = [];
     for (var i = 0; i < this.numFields; i++){
          var f = this.getField(this.getNthFieldName(i)).name;
          if(f == "topPh2") fields.push(f);
     }     //end of for loop
     app.alert(fields);

Likes

Translate

Translate
Participant ,
Jan 15, 2020 Jan 15, 2020

Copy link to clipboard

Copied

LATEST

*Sigh*

This was easy. '=' is not a logical operator.... I needed '==':

     var fields = [];
     for (var i = 0; i < this.numFields; i++){
          var f = this.getField(this.getNthFieldName(i)).name;
          if(f == "topPh2") fields.push(f);
     }     //end of for loop
     app.alert(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