4

I am trying to put this JavaScript in Adobe as a calculation field. The point of this is to use Term, Amount Financed and APR (Interest Rate) to calculate a monthly car payment for a form I'm creating. All I want to know is what JavaScript code will work? PS. I have limited knowledge in JavaScript.

This code calculates $208.80 a month when the correct calculation in fact is $100 More...

APR Is .21, Term is 60, Amount to Finance is 10,000.00.

My current code below:

var R = Number(this.getField("APR").valueAsString);
var N = Number(this.getField("Term").valueAsString);
var P = Number(this.getField("AmountFinanced").valueAsString);
event.value = P * (R / 12), Math.pow(N, (1 + R)) / Math.pow(N, (1 + (R / 12) - 1));
halfer
  • 19,824
  • 17
  • 99
  • 186
ASP tech
  • 67
  • 6
  • 2
    It would be helpful if you add the formula you're trying to implement in `event.value` – Dr. Acula Jun 01 '20 at 05:09
  • (When writing in English, there's nearly no need to Write With Capital Letters On Everything - it makes a question harder to read and harder to edit. Even titles don't need it these days. Please just use ordinary sentence case for your future questions, thanks). – halfer Jun 01 '20 at 07:50
  • Could you add a JS runnable example in the question itself? Click on the `<>` icon and it will take you to a browser JS/HTML editor. – halfer Jun 01 '20 at 07:53
  • im not sure what im being asked, i was hoping someone would shed some light incase im missing a figure in this code and if someone can rewrite it just to calculate a monthly payment for a loan, the 3 fields, APR,Term, and AmountFinanced are 3 separate fields in an adobe fallible pdf. please help. – ASP tech Jun 02 '20 at 04:36
  • also the code im using is written above, here is a link on youtube where i got my information from, just incase i misunderstood something, -> https://www.youtube.com/watch?v=Pgot9V7uZXw – ASP tech Jun 02 '20 at 04:41
  • If i was to write out the equation i think is being displayed: `Amount Financed = 10,000 * 21%/12 * 60*^ (60*(1+21%) /^*60(1+21%/12-1)` Not sure if this is completely wrong or not... – ASP tech Jun 02 '20 at 05:40

1 Answers1

6

Looks like you're trying to implement this:

formula

That would look something like

P * (R/12) * (Math.pow((1 + (R/12)), N))/ ((Math.pow((1 + (R/12)), N)) - 1)
Dr. Acula
  • 469
  • 6
  • 13
  • I FREAKING LOVE YOU, thats really close, i think im missing some small contingency such as 365 day cycle and 30 day until 1st payment calculation field, ill be working on it to perfect, I Really Appreciate the help, as im a newbie to javascript. ill be sure to come back and share this completed code! – ASP tech Jun 03 '20 at 05:02
  • Only $6.00 away! – ASP tech Jun 03 '20 at 05:08
  • 1
    Correction! It Works Perfectly, Its Calculated at 30 days, THANK YOU! – ASP tech Jun 03 '20 at 05:10