0
Participant
,
/t5/acrobat-sdk-discussions/help-with-for-loop-field-names/td-p/10858809
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:
What am I doing wrong here?
TOPICS
Acrobat SDK and JavaScript
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
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);
Participant
,
LATEST
/t5/acrobat-sdk-discussions/help-with-for-loop-field-names/m-p/10858826#M8362
Jan 15, 2020
Jan 15, 2020
Copy link to clipboard
Copied
*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);
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

