4 Replies Latest reply on Mar 24, 2011 12:54 PM by csb102155

    Scripting for eliminating zeros

    csb102155 Level 1

      Hi, I have an adobe acrobat form (Acrobat Professional 8.0) and I've added the javascript to calculate a column of fields.  I used this code:

       

      var f = this.getField("MSFund");
      var a = f.getArray();
      var sum = 0;
      for (i = 0; i < a.length; i ++)
      sum += a[i].value;
      event.value = sum;

      When I try to put in a code to hide zeros in this same field, I get a synpax error message.  Does anyone know the proper code for hiding zeros and where would I add it in this script mentioned above?

       

      Thanks for any assistance you can give on this.

       

      Connie

        • 1. Re: Scripting for eliminating zeros
          try67 MVP & Adobe Community Professional

          Add this at the end:

           

          if (event.value===0) event.value = "";

          • 2. Re: Scripting for eliminating zeros
            csb102155 Level 1

            Thanks for your quick response.  However, now, not only does the form not calculate, but it doesn't hide the zeros either.  Is the code appropriate?  What I want is to total a column of fields and hide the zeros.

             

            This is the script;

             

            var f = this.getField("MSFund");

            var a = f.getArray();

            var sum = 0;

            for (i = 0; i < a.length; i ++)

            sum += a[i].value;

            event.value = sum;

            var sum = 0;

            if (event.value===0) event.value = "";

             

            Thanks much for your help.

             

            Connie Bretes

            • 3. Re: Scripting for eliminating zeros
              gkaiseril MVP & Adobe Community Professional

              What error code and what coding statements?

               

              var f = this.getField("MSFund");
              var a = f.getArray();
              var sum = 0;
              for (i = 0; i < a.length; i ++)
              sum += a[i].value;
              event.value =  sum == 0? "" : sum; // use null string for zero result

               

              Or:

               

              var f = this.getField("MSFund");
              var a = f.getArray();
              var sum = 0;
              for (i = 0; i < a.length; i ++)
              sum += a[i].value;

              if (sum == 0)

                 event.value = ""; null zero result

              else
                 event.value = sum; // display result

               

              You might want to open the JS debugging console and see if you have any errors. Acrobat JS stops working as soon as any error is encountered.

              1 person found this helpful
              • 4. Re: Scripting for eliminating zeros
                csb102155 Level 1

                Thank you for your assistance.  I finally got it to work!

                 

                Connie