1 Reply Latest reply on Oct 23, 2015 6:57 PM by George_Johnson

    Need help to sum and then average 6 text boxes

    bsquared98

      My HR department dropped this one on my lap about 3 this afternoon and need it ASAP to develop training.  I'm stuck and am reaching out for help with it.

       

      We have a pdf form for employee evaluation.  In the piece in question, there are 6 sections and the employee is to rate themselves on a scale of 1 to 5 as to how fully they met the objectives in question.  The problem is that not everyone will fill out all six sections as they don't always apply to everyone.  Some people may fill out all 6 but some may also do 4 or 3.  So what I need to figure out is how to average out the scores we do get.  Summing is the easy part - but I can't figure out how to tell how many ratings have been filled in so I'll know how may fields I have to divide into the total in order to get the average rating for the bunch.  It's basically like the image below, so any help anyone could offer would be greatly appreciated.

       

      rating.png

        • 1. Re: Need help to sum and then average 6 text boxes
          George_Johnson MVP & Adobe Community Professional

          You'll have to use a custom calculation script, something like:

           

          // Custom calculation script for a text field

          (function () {

           

              // Set up some variables

              var nCount = 0;  // Number of non-bank fields

              var nSum = 0;  // Sum of non-bank fields

              var aFieldnames = ["grow", "Build", "finance", "impact", "culture", "other"];

              var i, f;

           

              // Loop through the fields named in the array

              for (i = 0; i < aFieldnames.length; i += 1) {

           

                  // Get a reference to the current field

                  f = getField(aFieldnames[i]);

           

                  // If the field is not empty...

                  if (f.valueAsString) {

                      nCount += 1;    // Increment the count of non-bank fields

                      nSum += +f.value;   // Add the field value to the running total

                  }

           

              }

           

              // Calculate the average

              if (nCount > 0) {

                  event.value = nSum / nCount;

              } else {

                  event.value = "";  // Blank this field if all fields are blank

              }

           

          })();