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

Loop Through Fields

Participant ,
Jan 15, 2020 Jan 15, 2020

Can someone help me come up with a console code that prints the name of each field? I had it just hours ago, and I cannot locate it again, nor come up with it on my own.

TOPICS
Acrobat SDK and JavaScript
3.6K
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
Community Expert ,
Jan 15, 2020 Jan 15, 2020

In the Acrobat Javascript Reference look at the method getNthFieldName

 

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
Participant ,
Jan 15, 2020 Jan 15, 2020

Right. So I need help fixing this:

for(var i = 0; i < this.numFields; i++){
console.println(i + ": " + this.getNthFieldName(i));
}
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
Participant ,
Jan 15, 2020 Jan 15, 2020

Or even directly from the JS Ref:

for (var i = 0; i < this.numFields; i++)
console.println("Field[" + i + "] = " + this.getNthFieldName(i));

 I think I don't understand console exactly right. I put that in, highlight it all, and hit ctrl+enter. I get undefined.

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
Community Expert ,
Jan 15, 2020 Jan 15, 2020

Did you open a document with form 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
Participant ,
Jan 15, 2020 Jan 15, 2020

I want to see a list of field names and their index numbers. A loop similar to this one was printing 31 lines of field names for me earlier, but I can't replicate it or find it again.

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
Community Expert ,
Jan 15, 2020 Jan 15, 2020

The code above should work. Make sure you select all of it before pressing Ctrl+Enter, though.

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
Community Expert ,
Jan 15, 2020 Jan 15, 2020
LATEST

You'll find a free tool here called "Find Required Fields". It loops through all the fields on a form and displays the ones that are required in a dropdown menu. It can easily be modified to show fields with any characteristic, or all of them.

https://www.pdfscripting.com/public/Free_Acrobat_Automation_Tools.cfm

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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