I have converted a excel spreadsheet to an Adobe Acrobat 8 form. I am trying to recreate the calculations within the form using Javascript. Unfortunately, I do not know the Javascript language. I have completed most of the spreadsheet by trial and error. Now I have two scripts I need help with.... The first is the mortgage payment script. This is what I have thus far...and it's not working
var a=this.getField("ir");
var b=this.getField("np");
var c=this.getField("PV");
event.value=(PMT=(a.value*(c.value)*Math.pow((a.value+1),b.value)))/((a.value+1)*(Math.pow((a.value+1),b.value)-1));
The other problem is on a debt to income ratio calculation. The calculation works but I need to do some kind of size and/or stacking code...since it errors when I delete one of the variable from the equation to reset the form.
var a=this.getField("Total Mo Income1");
var b=this.getField("Total Mo Expenses");
var c=this.getField("Debt to Income Ratio");
event.value=c.value= (b.value/a.value);
Any HELP would be greatly appreciated as I am losing sleep over search for the proper scripting! Thanks Much!!!!
[link=mailto:bmiller [at] lynkfinancial [dot] com]bmiller [at] lynkfinancial [dot] com[/link]
There aren't any scripting issues with the first calculation. What's the problem?
The second calculation has a divide by zero issue. One way to deal with this is to provide a default value to guard against resets. Something else to consider is testing "a.value" before doing the calculation.
if(a.value == 0 || isNaN(a.value))
event.value = "NA";
else
... do calculation ...
You could also force the "Debt to Income Ratio" field to always be a valid value by using the "Validate" event on this field.
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script