title: How can I add javascript to a PDF document to count the number of checked boxes and enter the value into a textbox area?
body: <p>So I have a PDF doc that has 25 check boxes called "cb1" through "cb25".  I would like to be able to count the number of boxes that are checked and put that count into a text box area called "Points".</p>
  
  <p>I'm not very familiar with either JS or PDF form creation but from what I've been able to dig up I think I'm close to getting it to work.</p>
  
  <p>I have added the following code to the document level:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function CountCheckBoxes(aFieldsNames) {
      // count field names that have been selected
      var count = 0;
      // loop through array of field names
      for (i = 0; i &lt; aFieldNames.length; i++) {
        // for field names with a value of not Off increment counter
        if (this.getField(aFieldNames[i]).value != "Off") count++;
      } // end loop of field names
      // return count
      return count;
    } // end CountCheckBoxes</code></pre>
  </div>
  </div>
  </p>
  
  <p>I've tried adding the following code text box properties to execute JS on mouse up and as a calculated value, neither of which seem to work to populate the text box with a count of checked boxes.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// var define field names to be tested
  var aFields = new Array('cb1', 'cb2', 'cb3', 'cb4', 'cb5', 'cb6', 'cb7', 'cb8', 'cb9', 'cb10', 'cb11', 'cb12', 'cb13', 'cb14', 'cb14', 'cb15', 'cb16', 'cb17', 'cb18', 'cb19', 'cb20', 'cb21', 'cb22', 'cb23', 'cb24', 'cb25');
  // count field names that have been selected
  event.value = CountCheckBoxes(aFields);</code></pre>
  </div>
  </div>
  </p>