7 Replies Latest reply on Oct 25, 2010 2:39 AM by mrs daniels

    Need a script to count certain fields for a total?

    mrs daniels Level 1

      I know absolutely nothing about scripting.  I am sure Acrobat can do this and it would save me a ton of time.

      I current have radial buttons on my form -- Jobs, Proof, MISC, RP/RS -- Each button has a different value from 1 to 4.

      I would like a script that will count how many Job buttons are checked (value=1), etc.  Also if no buttom is selected then do not count them.

       

      My pdf is called test log.pdf and the button group is called type 1.0, the next grouping is type 1.1 -- 10 on a page (type 1.9).  Then each group has 4 buttons.

       

      I would be willing to send to form if anyone is interested.  It will probably to an experienced person just a few minutes to write a script where for me I have been trying for months.

       


      Thanks,

      brenda

        • 1. Re: Need a script to count certain fields for a total?
          try67 MVP & Adobe Community Professional

          Here's a script that will count how many of the radio-buttons are set to

          "1". You can set it as the custom calculation script of a text field.

           

          var counter = 0;

          for (i=1; i<=9; i++) {

              if (this.getField("type 1." + i).value=="1") counter+;

          }

           

          if (counter>0) {

              event.value = counter;

          } else event.value = "";

          • 2. Re: Need a script to count certain fields for a total?
            mrs daniels Level 1

            It works!! How cool.  Thanks so much.

             

            I have been trying different things for a couple months now.

            I would have never got this.

             

            brenda

            • 3. Re: Need a script to count certain fields for a total?
              try67 MVP & Adobe Community Professional

              Again, the forum changed my script, thus ruining it...

              It should be counter++ , of course, not counter+ .

              • 4. Re: Need a script to count certain fields for a total?
                mrs daniels Level 1

                Okay,

                So now to make it a little more complicated ---

                 

                1.   I have 3 pages in my Acrobat file, so what needs to be added to the

                script so that is looks at all three pages?

                 

                 

                2.   The field "type 1.0 - type 1.9"  that is on the 1st page -- then page 2

                is "type 1.0a - type 1.9a"  and page 3 is "type 1.0b - type 1.9b".

                 

                What needs to be added to the code for this?

                 

                 

                I will probably have a few more questions once I get further into more form.

                But it is starting to make a little sense to me.

                 

                Thanks

                brenda

                • 5. Re: Need a script to count certain fields for a total?
                  try67 MVP & Adobe Community Professional

                  It doesn't matter which page the fields are on.


                  If you want to look for fields "type 1.0a" to "type 1.9a", you need to  adjust this line of the script like so:

                  if (this.getField("type 1."+i+"a").value=="1") counter++;
                  • 6. Re: Need a script to count certain fields for a total?
                    mrs daniels Level 1

                    I tried adding the "a" and it didn't work.

                    I also need a script for checkboxes.

                     

                    I have attached my acrobat pdf trial log.

                    It consist of three pages.

                    I have 3 sticky notes at the bottom of the first page --

                            the JOB count is almost there -- just need to count all three pages.

                            the PIECE sum was easy - automatic script

                            the MAC STATUS needs a script -- this is a checkbox.

                     

                    Please take a look and see what you can do.  I really do appreciate all the

                    help.

                     

                    brenda

                    • 7. Re: Need a script to count certain fields for a total?
                      mrs daniels Level 1

                      Got this to work.   (try67 gave me base).

                       

                      Used the following:

                       

                      var counter = 0;
                      for (i=0; i<=9; i++) {
                          if (this.getField("type 1."+i).value=="1") counter++;
                          if (this.getField("type 1."+i+"a").value=="1") counter++;
                      if (this.getField("type 1."+i+"b").value=="1") counter++;
                      }

                      if (counter>0) {
                          event.value = counter;
                      } else event.value = "";

                       

                       

                       

                      The text in blue would be changed to match your form.   type 1.0 - type 1.9 was my field names on page 1; then on page 2 they were type 1.0a - type 1.9a

                      So I duplicated the "if" line for each page -- I'm sure there is an easier way but this worked; the other suggestion I got didn't work.

                       

                      Then I had 4 item for the radial button group -- so they had the values 1, 2, 3, 4 -- so I just changed the value for each.

                       

                      My Results looked something like this:  (where Jobs, Proofs, Misc, RP/RS were radial buttons that were choosen.)

                       

                      Jobs = 4   Proofs= 2  Misc=3   RP/RS = 1