3 Replies Latest reply on Jan 5, 2015 4:12 PM by gkaiseril

    Counting Checkboxes

    oodles798

      I'm not that familiar with JavaScript... I have a form I want to make with 18 questions, and each question has three checkboxes with the same name, and each checkbox has a unique export value. Only one checkbox per question can be selected. One box is for yes, another no, and another for n/a.

       

      I'm trying to figure out how to look at all the checkboxes in the form and then return the number of yes, no, and n/a selected respectively in separate text boxes. I can't quite make sense of how to do it.

        • 1. Re: Counting Checkboxes
          gkaiseril MVP & Adobe Community Professional

          What can you not figure out?

           

          Can you get the field object?

           

          Can you get the value of the field object?

           

          Can  you use an if statement to select an item?

           

           


          • 2. Re: Counting Checkboxes
            oodles798 Level 1

            So I tried this...

             

            function countCheckedBoxes()

             

            {

            var counter = 0;

            for (var i =0 ; i < this.numFields ; i++) {

            var q = this.getField(this.getNthFieldName(i));

            if (q.type == "checkbox") {

            if (q.value != "No") {

            if (q.exportValue = "Yes"){

            counter++;

            }

            }

            }
            }

            }

             

            Doesn't work. Am I even in the right ballpark?

            • 3. Re: Counting Checkboxes
              gkaiseril MVP & Adobe Community Professional


              Are you trying to count both the "Yes" and "No" check boxes together or just count the specific selected answer?

               

              For "Yes":

               

              var counter = 0;

              for (var i =0 ; i < this.numFields ; i++) {

              var q = this.getField(this.getNthFieldName(i));

              if (q.type == "checkbox") {

              if (q.value.toLowerCase() = "yes") {

                  counter++;

                   } // yes value;

                 } // check box;

              } // end field loop;

              event.value = counter;