2 Replies Latest reply on Jun 23, 2011 6:22 AM by RenéG

    Total number added automatically

    RenéG Level 3

      HI,

       

      I have a pdf that has 15 text fields vertically alligned and underneath that I have another field named: TOTAL #

       

      What I want is if the customer fills up, let's say 4 of these vertically aligned fields, then I want the numeral "4" to appear in the "TOTAL #" field.

       

      What would be the script for that?

       

      Thanks a lot.

        • 1. Re: Total number added automatically
          gkaiseril MVP & Adobe Community Professional

          // custom calculation script for field "Total #"

          function CountFields(aFields) {
          var nFields = 0;
          for(i = 0; i < aFields.length; i++) {
          try {
          // count non null values;
          if(this.getField(aFields[i]).value != "") nFields++;
          } catch(e) {
          if(e['message'] == "this.getField(aFields[i]) has no properties") app.alert("unknown field name: " + aFields[i]);
          else app.alert(e.toString());
          } // end catch
          } // end for aFields
          return nFields;
          }

           

          // create array of field names to count
          var aNames = new Array("Text1", "Text2", "Text3", "Text4", "Text5", "Text6",

          "Text7",  "Text8",  "Text9",  "Text10",  "Text11",  "Text12",  "Text13", "Text14",

          "Text15" );
          // count the non-null fields;
          event.value = CountFields(aNames);

           

          You will need to change the name of the field names.

          • 2. Re: Total number added automatically
            RenéG Level 3

            Wonderful! Thanks.