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

Help With For Loop, Field Names

Participant ,
Jan 15, 2020 Jan 15, 2020

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.pngexpand image

 

What am I doing wrong here?

TOPICS
Acrobat SDK and JavaScript
777
Translate
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);
Translate
Participant ,
Jan 15, 2020 Jan 15, 2020
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);
Translate
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