2 Replies Latest reply on Aug 29, 2014 9:45 AM by Chickenman13

    Writing an equation in JavaScript for a loan agreement

    Chickenman13

      Hello,

       

      I am having trouble putting an equation into JavaScript form. I am trying to calculate how much a loan will cost with a fixed interest over a set period of time.

      So we've got the equation: FutureValue = PresentValue(1 + InterestRate)^LoanTerm

      With the fields in my form, I believe it would look like this: Ttl = AmountFinanced(1 + Rate)^NumberofPaymentsRow1

      My JavaScript for my form named "Ttl" currently looks like this: AmountFinanced * Math.pow(1 + Rate, NumberofPaymentsRow1)

           - Unfortunately it is not returning a value and I have run out of ideas. I'm not sure where I'm going wrong and any help would be appreciated.

       

      javahelp.png

        • 1. Re: Writing an equation in JavaScript for a loan agreement
          gkaiseril MVP & Adobe Community Professional

          Do you get any errors popping up?

           

          Have you checked the JavaScript console for errors?

           

          The Custom JavaScript calculation option requires the full JavaScript coding and it is not a front end process gathering parameters for processing like the first two calculation options. You need to write the complete JavaScript code not some shorthand .

           

          JavaScript is an object orientated language, so you need to establish the connection to a field object before you can access the value property of the field. You need to use the 'doc.getField(cName)' method to acquire the field object.

           

          You also need to specify the target or object into which you want to place the result.

           

           

          event.value = this.getField("AmountFinanced").value * Math.pow(1 + this.getFieldI"Rate').value, this.getField("NumberofPaymentsRow1").value) ;

           

          Note that JavaScript is case sensitive for field names, variable names, function names, etc.

          • 2. Re: Writing an equation in JavaScript for a loan agreement
            Chickenman13 Level 1

            Thanks! That really helped. I have really had no experience with JavaScript before yesterday, so I appreciate you showing me the correct methodology.

             

            Here's what I ended up using: event.value = this.getField("AmountFinanced").value * Math.pow(1 + this.getField("Rate").value, this.getField("NumberofPaymentsRow1").value/12) ;

             

            The /12 made was to get the term in years rather than payment installment. Thanks again.