Skip navigation
Miss Caroline
Currently Being Moderated

Field count

Dec 20, 2011 5:09 AM

Tags: #count #javascript #table #format #rows #pdf_forms #syntax #livecycle_es2

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

 
Replies
  • Currently Being Moderated
    Dec 20, 2011 6:46 AM   in reply to Miss Caroline

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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 20, 2011 1:42 PM   in reply to Miss Caroline

    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;

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 23, 2011 5:51 AM   in reply to Miss Caroline

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points