Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Field count

Avatar

Level 2

I need to track the number of Yes, No, and Checkbox selections made in a multiple page form. These need to be counted individually and summed for a total count to be displayed on the final page of the document. In other words, Yes was selected 10 times; No was selected 5 times; Checkbox was selected 4 times. 19 total selections were made. Can someone please help me with the javascript syntax to access the fields to insert these figures on the final page? The final form will be a .PDF created using Adobe LiveCycle Designer ES2.

This is the form hierarchy:

form1

Tables_P1

tblStatP1

Row1

Yes

No

RadioButtonList1

Checkbox1

1 Accepted Solution

Avatar

Correct answer by
Level 2

The correct result is below. The only thing I was doing wrong in my code was putting the 1 in parenthesis. Thanks, Radzmar, for your help!

var nYes = 0;

var nNo = 0;

var nChk = 0;

for (i=1; i<=26; i++)

{

if(xfa.resolveNode("Page1.RadioButtonList"+i).rawValue === "Yes")

{

  nYes++;

}

if(xfa.resolveNode("Page1.RadioButtonList"+i).rawValue === "No")

{

  nNo++;

}

if (xfa.resolveNode("Page1.CheckBox"+i).rawValue === 1)

{

  nChk++;

}

}

this.rawValue = nYes + nNo + nChk;

View solution in original post

7 Replies

Avatar

Level 6

Does each page have its own table (Tables_P2, etc) or is it all one big table?

Avatar

Level 10

You can use a loop to check all check button objects (check box and radio buttons) within your form.

Here's an example.

Avatar

Level 2

Okay... I had to redo the format of the entire form for reasons I won't go into.I'm no longer working with tables. The radio buttons, checkboxes, and numeric field are now on the same hierarchy level. This is the code I tried:

//initialize counts
var nYes = 0;
var nNo = 0;
var nChk = 0;
var nTotal = 0;

for (i=1; i<=26; i++)

     {
           if (("RadioButtonList"+i).rawValue = Yes)
           {
            nYes++;
           }
           else if (("RadioButtonList"+i).rawValue = No)
           {
            nNo++;
           }
           else if (("CheckBox" + i).rawValue = 1)
           {
            nChk++;
           }
     }


nTotal = nYes + nNo + nChk;
this.rawValue = nTotal;

I'm getting nothing.

Avatar

Level 10

Your script will not work, as you cannot use a variable in JavaScript to resolve a node.

Use the resolveNode method to use variables in the expression.

Also, to campare a value you have to use "===" or "==" instead of "=".

//initialize counts
var nYes = 0;
var nNo = 0;
var nChk = 0;
var nTotal = 0;

for (i=1; i<27; i++)

     {
           if (xfa.resolveNode("RadioButtonList[" + i + "]").rawValue === "Yes")
           {
            nYes++;
           }
           else if (("RadioButtonList[" + i + "]").rawValue === "No")
           {
            nNo++;
           }
           else if (("CheckBox[" + i + "]").rawValue === 1)
           {
            nChk++;
           }
     }


nTotal = nYes + nNo + nChk;
this.rawValue = nTotal;

Did you test the script I posted before? It will look for all checkButton objects in the whole form, no matter if in tables or subforms.

Avatar

Level 2

I did test your code and the form froze up and shut down LiveCycle. I copy and pasted your edits to my code and still nothing. There must be something small I'm missing. I probably won't get a chance to look at this again until Tuesday. I hope you'll be available to help me then. Thank you SO much!

Tuesday:

Okay, I have this code working except for the nChk portion. Since it's a check box, do I need to do something different with the comparison code?

var nYes = 0;
var nNo = 0;
var nChk = 0;
for (i=1; i<=26; i++)
{
   if(xfa.resolveNode("Page1.RadioButtonList"+i).rawValue === "Yes")
   {
    nYes++;
   }
   if(xfa.resolveNode("Page1.RadioButtonList"+i).rawValue === "No")
   {
    nNo++;
   }
   if(xfa.resolveNode("Page1.CheckBox"+i).rawValue === "1")
   {
    nChk++;
   }
}

this.rawValue = nYes + nNo + nChk;

Avatar

Correct answer by
Level 2

The correct result is below. The only thing I was doing wrong in my code was putting the 1 in parenthesis. Thanks, Radzmar, for your help!

var nYes = 0;

var nNo = 0;

var nChk = 0;

for (i=1; i<=26; i++)

{

if(xfa.resolveNode("Page1.RadioButtonList"+i).rawValue === "Yes")

{

  nYes++;

}

if(xfa.resolveNode("Page1.RadioButtonList"+i).rawValue === "No")

{

  nNo++;

}

if (xfa.resolveNode("Page1.CheckBox"+i).rawValue === 1)

{

  nChk++;

}

}

this.rawValue = nYes + nNo + nChk;