2 Replies Latest reply on Dec 8, 2017 2:38 PM by jeffreys64799875

    Custom Form calculation appending last added value


      Hello everybody,


      I'm getting some weird behavior when doing a custom calculation for a form field. Here is the Javascript I'm inputting:



      (this.getField("Purchase price").value-

      this.getField("Loan amount").value-

      this.getField("Additional loans").value-


      this.getField("Seller credits").value-

      this.getField("Agent credits").value+

      this.getField("Reserve req").value+

      this.getField("Closing costs").value)


      The problem is, the last field's value is appending to the calculated values above it. So everything calculates and display in the form field (except closing costs), and when Closing costs is filled in, the value gets appending rather than adding to the rest of the values like it should. Does anyone know how to fix this problem, or does anyone have any idea what is going on?


      Thank you!

        • 1. Re: Custom Form calculation appending last added value
          try67 MVP & Adobe Community Professional

          The + operator has a dual functionality in JS. When used with strings it appends them to each other (eg. "a"+"b" will return "ab"), and when used with numbers it will add them up (eg. 1 + 2 will return 3). If you use it on a string and a number it will convert the number to a string and append them, so 1 + "a" will return "1a". Even "1" + 2  will return "12", not 3.

          So the solution is to explicitly convert all the values in your code to numbers, to make sure they are added up and not appended (in case any of them are strings).

          To do that add a Number constructor around each value, like this:

          Number(this.getField("Purchase price").value)

          1 person found this helpful
          • 2. Re: Custom Form calculation appending last added value
            jeffreys64799875 Level 1

            Ah ha! That was actually what I figured was happening. I believe it has to do with the fact that some of the fields were being pasted in from another form.


            Let me just say thank you for your quick response, and thorough explanation. I love Adobe software, and the community behind it!