7 Replies Latest reply: Dec 28, 2011 9:38 AM by Miss Caroline RSS

    Field count

    Miss Caroline

      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. Re: Field count
          Kevin Cavallo Community Member

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

          • 2. Re: Field count
            Miss Caroline Community Member

            Each page has its own table.

            • 3. Re: Field count
              radzmar CommunityMVP

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

              Here's an example.

               

              function countChk(vNode) {

                        if (vNode.className === "field") {

                                  if (vNode.ui.oneOfChild.className === "checkButton") {

                                            if (vNode.items.nodes.length > 1) {

                                                      if (vNode.value.oneOfChild.value == 1) {

                                                                nChk++;

                                                      }

                                            } else {

                                                      if (vNode.value.oneOfChild.value == 1) {

                                                                nYes++;

                                                      } else if (vNode.value.oneOfChild.value == 2) {

                                                                nNo++;

                                                      } else {

                                                                nNone++;

                                                      }

                                            }

                                  }

                        }

                        for (var i = 0; i < vNode.nodes.length; i++) {

                      countChk(vNode.nodes.item(i));

                        }

              }

               

               

              var nYes = 0;

              var nNo = 0;

              var nNone = 0;

              var nChk = 0;

              countChk(xfa.form);

               

               

              Textfield1.rawValue = nYes + " | " + nNo + " | " + Math.floor(nNone / 2) + " | " + nChk;

              • 4. Re: Field count
                Miss Caroline Community Member

                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.

                • 5. Re: Field count
                  radzmar CommunityMVP

                  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.

                  • 6. Re: Field count
                    Miss Caroline Community Member

                    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;

                    • 7. Re: Field count
                      Miss Caroline Community Member

                      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;