6 Replies Latest reply on Jun 28, 2013 9:56 AM by kabotsi7521

    Using Custom Calculation Script box in Acrobat Pro X

    kabotsi7521

      I would like to simply subtract several fields from one field and have the result show up in final/total field when a user clicks her mouse in the field. I have used the custom calculation script. What is wrong with the code below? Without the <script></script> it doesn't work; with it, it  complains about a missing } at the end. I am an extreme novice with JavaScript, but it doesn't appear to me that I'm missing a }.

       

      <script type="text/JavaScript">

      function(){

      event.value = this.getField("Total College Expense").value - this.getField("Less Prepaid Total").value - this.getField("Less Procurement Card").value - this.getField("Less Advances").value - this.getField("Amount Due: College").value;

      }

      </script>

       

      Thanks for any help you can offer!

       

      Kirsten

        • 1. Re: Using Custom Calculation Script box in Acrobat Pro X
          George_Johnson MVP & Adobe Community Professional

          It should be:

           

          event.value = this.getField("Total College Expense").value - this.getField("Less Prepaid Total").value - this.getField("Less Procurement Card").value - this.getField("Less Advances").value - this.getField("Amount Due: College").value;

          • 2. Re: Using Custom Calculation Script box in Acrobat Pro X
            kabotsi7521 Level 1

            Thanks, George. No more complaints about missing }, but it still doesn't calculate when I click or tab into the field. Do I need to do anything else with the other fields (e.g. "Total College Expense" "Less Procurement Card," etc.)?

            • 3. Re: Using Custom Calculation Script box in Acrobat Pro X
              George_Johnson MVP & Adobe Community Professional

              A calculation script is triggered whenever any field value is changed, not when the field to which it is attached receives the focus. Calculated fields should normally be set to read-only so that a user does not attempt to change the value. Can you explain why you want the user to click into the field?

              • 4. Re: Using Custom Calculation Script box in Acrobat Pro X
                kabotsi7521 Level 1

                Right now, the calculation script is attached ONLY to the field where I want the total to appear (Amount Due: Employee). Is that wrong? I assumed (probably mistakenly) that the total would appear when the user clicked in the field on the form. Do I need to somehow have the Amount Due: Employee in the script?

                 

                I do see a checkbox for Locked in the Text Field Properties dialogue. I guess that needs to be checked for the total field and does it need to be checked for the other fields, too?

                • 5. Re: Using Custom Calculation Script box in Acrobat Pro X
                  gkaiseril MVP & Adobe Community Professional

                  Acrobat uses a special variation of JavaScript. You do not need all of the web tags.

                   

                  Drop the "<>" tags.

                   

                  You have defined an unnamed function but have not called the function for execution. If you do not want to name the function then use the anonymous function:

                   

                  (function(){

                  event.value = this.getField("Total College Expense").value - this.getField("Less Prepaid Total").value - this.getField("Less Procurement Card").value - this.getField("Less Advances").value - this.getField("Amount Due: College").value;

                  }) ();

                   

                  This may speed up the calculation but it will make debugging scripting errors more difficult.

                   

                  You can also just perform the calculation without a function:

                   

                  event.value = this.getField("Total College Expense").value - this.getField("Less Prepaid Total").value - this.getField("Less Procurement Card").value - this.getField("Less Advances").value - this.getField("Amount Due: College").value;

                   

                  Locking the field or making the field "Read Only" will not affect the running of the script.

                   

                  Try clearing the form and reenter the data and not the changes in the calculation field. If there are multiple calculations or other scripts, an error in another script may prevent the execution of the calculation or the order of the fields using calculations may not be in the required sequence.

                   

                  Open the JavaScript console, Ctrl + J and see there are any error messages.

                  • 6. Re: Using Custom Calculation Script box in Acrobat Pro X
                    kabotsi7521 Level 1

                    Thanks! GKaiseri. JavaScript debugger helped me see that I didn't have the complete names for a couple of the fields. It's working now!