2 Replies Latest reply on Sep 25, 2010 10:41 AM by sboyse

    Special Formatting after Simple Calculation


      I've got a set form field that each asks for a numbers, does some math, and displays the results in a separate field.


      What I'd like it to do is simply add together all the inputs (not a problem) but then take the result and modify them as follows: If you can subtract 5 from the result and still get a positive real number, it also displays those number after it.


      For example:


      Input 4

      Output w/formatting: +4


      Input: 8

      Output w/formatting: +8/+3


      Input: 5, 3, 6, 7

      Output w/formatting: +21/+16/+11/+6/+1


      I'm beat after a days worth of syncing up fields, if someone could lob this one over the plate for me, I'd really appreciate it.


      (Adobe Acrobat 9 Pro)

        • 1. Re: Special Formatting after Simple Calculation
          George_Johnson MVP & Adobe Community Professional

          You can use the following as the custom Format script of the Total field, but you owe me a six-pack.


          (function () {


              // do nothing if field is blank

              if (!event.value) return;


              // get field value as a number

              var num = +event.value;


              var d = 5;          // divisor

              var s = "+" + num;  // begin building output string

              var it;             // number of iterations


              // determine remainder

              var r = num % d;


              // if remainer is not less than divisor...

              if (r !== num) {


                  // determine number of iterations

                  it = (num - r) / d;


                  // build up output string

                  for (var i = 0; i < it; i += 1) {


                      s += "/+" + (num - (d * (i + 1)));





              // display output string

              event.value = s;




          This code is based on the assumption that the input is a positive integer. If you don't already enforce that with a Keystroke/Validate script on this or other fields that this field value is based upon, you should.

          • 2. Re: Special Formatting after Simple Calculation
            sboyse Level 1
            If you don't already enforce, you should

            Done, and also that worked perfectly. Gotta love the people on Adobe forums, first rounds on me!