title: Can I create array based on field names that exist in PDF?
body: <p>I am trying to count the number of a specific field which is not empty and would like to use an array to store the field names based on whether they exist in the PDF form. </p>
  
  <p>My code looks like this so far and it works as long as the field names in the array exists, if that field does not exist then the code breaks.</p>
  
  <p>The SiteDeficiency_DeficiencyNumber_# could have 0 instances or anywhere up to 50 instances or so.</p>
  
  <p>I did find that you can check if a name exists with this code but I can't seem to get it to work.</p>
  
  <p>Any help is appreciated. I have coded simple things but maybe this is just too advanced for me.</p>
  
  <p><strong>This is what my code looks like so far:</strong></p>
  
  <pre><code>var aFields = new Array("SiteDeficiency_DeficiencyNumber_1",
  "SiteDeficiency_DeficiencyNumber_2",
  "SiteDeficiency_DeficiencyNumber_3",
  "SiteDeficiency_DeficiencyNumber_4",
  "SiteDeficiency_DeficiencyNumber_5",
  "SiteDeficiency_DeficiencyNumber_6");
  
  var count = 0;
  
  for (i = 0; i &lt; aFields.length; i++) { 
      if (this.getField(aFields[i]).valueAsString != "") count++ 
  } 
  </code></pre>
  
  <p>event.value = count; </p>
  
  <p><strong>I tried incorporating this too</strong></p>
  
  <pre><code>if(document.forms[0].SiteDeficiency_DeficiencyNumber_1)
  {
   ...
  } 
  </code></pre>
  
  <p>I would really like the array at the beginning to populate with only the SiteDeficiency_DeficiencyNumber_# fields that exist and then have the array looped through to count which fields are not blank.</p>
  
  <p>I tried doing this but still does not work.</p>
  
  <pre><code>var aFields = [];
  for(i = 1; i &lt;101; i++)
  {
      if(document.forms[0].("SiteDeficiency_DeficiencyNumber_"+i).valueAsString.length &gt; 0) //Checks if field exists
      {
          aFields.push("SiteDeficiency_DeficiencyNumber_"+i); //adds field name to array
      }
  }
  </code></pre>
  
  <p>var count = 0;</p>
  
  <pre><code>for (a = 0; a &lt; aFields.length; a++) { 
      if (this.getField(aFields[a]).valueAsString != "") count++ //counts field if not empty
  </code></pre>
  
  <p>} </p>
  
  <p>event.value = count;</p>