Most efficient way to loop through similarly named fields?

tehinternets 22-01-2015


I have a 5 page document with each page containing appx. 50 similarly named fields.    E.g. Viol1Num, Viol2Num, Vio3Num ...  Viol50Num.

I am looking for an efficient way of programming a loop to look at each field in Javascript so I can do some manipulations in those fields on what the user entered.

In FormCalc I've previously used the 'foreach' function similar to:

foreach (Field1, Field2, Field3.....Field50) do



however, that gets really lengthy, especially when dealing with subsequent pages where I have to start adding 'topmostSubform.Page2.' in front of each field name so that I can access from the first page all of the fields on subsequent pages.  Also, I need to do this in Javascript, not FormCalc.

For example, in JS I am using this loop to mark all fields as read only:

    for (var nPageCount = 0; nPageCount <; nPageCount++) {
   var oFields = xfa.layout.pageContent(nPageCount, "field");
   var nNodesLength = oFields.length;
   for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
   oFields.item(nNodeCount).access = "readOnly";

How could I do something similar to that so I could look through each field and perform actions on it without having to list out every single field name?

I tried altering that to look at fields instead of field properties, but I couldn't get it to run.


Accepted Solutions (1)

Accepted Solutions (1)

tehinternets 27-01-2015

I have solved my issue.   It took some battling in javascript using xfa.resolveNode.

I have 5 pages, each consisting of a series of 60 fields named Viol1Num, Viol2Num, Viol3Num .... Viol60Num.

If when this javascript runs, it detects a blank field, then insert a '3' into it.

The below is the javascript which runs for the second page of this document.

   while (LoopCounter < 61) {
   if ((LoopCounter != 21) && (LoopCounter != 22)) {
   if((xfa.resolveNode("topmostSubform.Page2.Viol" + LoopCounter + "Num").rawValue == null) | (xfa.resolveNode("topmostSubform.Page2.Viol" + LoopCounter + "Num").rawValue == "")) {
   xfa.resolveNode("topmostSubform.Page2.Viol" + LoopCounter + "Num").rawValue = 3;
   LoopCounter = LoopCounter + 1

Answers (2)

Answers (2)

tehinternets 27-01-2015

Thanks for the reply, however I'm still at a loss on how to implement what you're describing.  My Concerns are:

-My document seems to have 1 topmostSubform, and then 6 pages under.   Adobe/LiveCycle structure on how things like this work is not my string suit.  Would I have to have a subform for each page?

-If referencing by subform, I don't want ALL fields on the page.  There are many other fields not applicable to what I was asking on my original post and I wouldn't want to modify them; only a series of similarly named fields.