2 Replies Latest reply on May 20, 2008 7:37 PM by (Linda_Pearson)

    Need Help with Acrobat 8 Form Calculation Script

      I have some fields I need to do some calculations on and I have them all working except the last one.
      I have four fields:
      PAGE_TOTAL
      CASH_ADVANCE
      BAL_DUE_EMPLOYEE
      BAL_DUE_BUSINESS

      The page total pulls it's totals from the rest of the form and works fine.
      The cash advance is input by the employee (the amount of a cash advance they received before taking the trip.)
      The balance due the employee is page_total minus cash_advance and this works and I finally got it to put a 0.00 amount in the bal_due_business field.

      Now, I need it to check and if the cash advance is larger than the page total, then I need it to put 0.00 in bal_due_employee and put calculate the amount that will be due back to the business (cash_advance - page_total).

      Here is the script I am trying to use for the BAL_DUE_BUSINESS:
      IF event.value = this.getField("BAL_DUE_EMPLOYEE").value < 0.00;
      THEN
      event.value = this.getField("BAL_DUE_COLLEGE") == this.get.Field("CASH_ADVANCE").VALUE - this.getField("PAGE_TOTAL").value;
      AND
      event.value = this.getField("BAL_DUE_EMPLOYEE").value == 0.00;
      END;

      I get getting an error when I try to save this code. It keeps telling me:
      missing ; before statement 1: at line 2

      I have tried everything I can think of to redo this code and must get this form done. I can't figure out what is wrong.

      By the way, here is the code I am using for the BAL_DUE_EMPLOYEE field:
      event.value = this.getField("PAGE_TOTAL").value - this.getField("CASH_ADVANCE").value;
      AND
      event.value = this.getField("BAL_DUE_COLLEGE").value = 0.00;

      Please help.
        • 1. Re: Need Help with Acrobat 8 Form Calculation Script
          gkaiseril MVP & Adobe Community Professional
          The "statement" to be evaluated by an "if" statement must be between "(" and ")" it is not terminated with a ";" and there is no "THEN" key word. http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:if...else

          The "=" is an assignment operator not a comparison operator. http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Assignment_O perators

          The "==" is a comparison operator and not an assignment operator. http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Comparison_O perators

          You should have Adobe Acrobat" JavaScript Reference and Guide http://www.adobe.com/devnet/acrobat/javascript.html
          and Netscape's JavaSript Reference 1.5 http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference available when writing code.
          • 2. Re: Need Help with Acrobat 8 Form Calculation Script
            Level 1
            Geo, thank you for your answer and the links.
            Thanks to your help and your references, my form is working perfectly. This will make my bosses very happy. You are fantastic.

            Here is the code I am using now, in case someone else has this problem:
            /* Code for Balance due employee */
            event.value = this.getField("PAGE_TOTAL").value - this.getField("CASH_ADVANCE").value;
            if (event.value < 0) event.value = 0;

            /* Code for Balance due college */
            event.value = this.getField("CASH_ADVANCE").value - this.getField("PAGE_TOTAL").value;
            if (event.value < 0) event.value = 0;