Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 4 of 4
Thread: Need help modify code

10032011, 07:44 PM #1
 Join Date
 Oct 2011
 Posts
 1
 Thanks
 0
 Thanked 0 Times in 0 Posts
Need help modify code
Hi need help with a loan calculator script, i know the moderator frowns on such requests but i just have to, im willing 2 buy a cup of coffee if it works, i want the code below to display the total loan repayment amount instead of the monthly payment payment = principle * monthly interest/(1  (1/(1+MonthlyInterest)*Months)) , eg if if l0an is 20$ payment is in 4 months, intrest rate is 15% display = amount to be repaid. thanks
Code:<script language="JavaScript"> <! function showpay() { if ((document.calc.loan.value == null  document.calc.loan.value.length == 0)  (document.calc.months.value == null  document.calc.months.value.length == 0)  (document.calc.rate.value == null  document.calc.rate.value.length == 0)) { document.calc.pay.value = "Incomplete data"; } else { var princ = document.calc.loan.value; var term = document.calc.months.value; var intr = document.calc.rate.value / 1200; document.calc.pay.value = princ * intr / (1  (Math.pow(1/(1 + intr), term))); } // payment = principle * monthly interest/(1  (1/(1+MonthlyInterest)*Months)) } // > </script> The results of this loan payment calculator are for comparison purposes only. They will be a close approximation of actual loan repayments if available at the terms entered, from a financial institution. This is being provided for you to plan your next loan application. To use, enter values for the Loan Amount, Number of Months for Loan, and the Interest Rate (e.g. 7.25), and click the Calculate button. Clicking the Reset button will clear entered values. <p> <center> <form name=calc method=POST> <table width=60% border=0> <tr><th bgcolor="#aaaaaa" width=50%><font color=blue>Description</font></th> <th bgcolor="#aaaaaa" width=50%><font color=blue>Data Entry</font></th></tr> <tr><td bgcolor="#eeeee">Loan Amount</td><td bgcolor="#aaeeaa" align=right><input type=text name=loan size=10></td></tr> <tr><td bgcolor="#eeeee">Loan Length in Months</td><td bgcolor="#aaeeaa" align=right><input type=text name=months size=10></td></tr> <tr><td bgcolor="#eeeee">Interest Rate</td><td bgcolor="#aaeeaa" align=right><input type=text name=rate size=10></td></tr> <tr><td bgcolor="#eeeee">Monthly Payment</td><td bgcolor="#eeaaaa" align=right><em>Calculated</em> <input type=text name=pay size=10></td></tr> <tr><td bgcolor="#aaeeaa"align=center><input type=button onClick='showpay()' value=Calculate></td><td bgcolor="#eeeeaa" align=center><input type=reset value=Reset></td></tr> </table> </form> <font size=1>Enter only numeric values (no commas), using decimal points where needed.<br> Nonnumeric values will cause errors.</font> </center> <p align="center"><font face="arial" size="2">This free script provided by</font><br> <font face="arial, helvetica" size="2"><a href="http://javascriptkit.com">JavaScript Kit</a></font></p>
10032011, 08:05 PM
#2
 Join Date
 Feb 2008
 Location
 Cebu City, Philippines
 Posts
 1,752
 Thanks
 65
 Thanked 372 Times in 365 Posts
What's the expected answer for ? (I have the script ready but since I'm not too smart in Algebra I might mess up):
eg if if l0an is 20$ payment is in 4 months, intrest rate is 15%
Learn how to javascript at 02geek
The more you learn, the more you'll realize there's much more to learn
Ray.ph
10032011, 09:05 PM
#3
http://www.juncojunction.com/juncoju...alculator.html
It's terribly out of date. It was written in 1998 for a contest where you were only allowed a maximum of 5k bytes to create an HTML page, so to make it fit it was compressed to the point where it's hard to read. And, of course, the JavaScript is designed for MSIE 4 and Netscape 4.
Still, it works, and works well.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
10032011, 09:21 PM
#4
To change the original code just do the following:
In the <form> part of the HTML add in one row, right after the payment row, as shown in red here:
(Notice that I did not attempt to change the HTML to modern standards. I left it as is.)Code:<tr> <td bgcolor="#eeeee">Monthly Payment</td> <td bgcolor="#eeaaaa" align=right> <em>Calculated</em> <input type=text name=pay size=10> </td> </tr> <tr> <td bgcolor="#eeeee">Total of Payments</td> <td bgcolor="#eeaaaa" align=right> <em>Calculated</em> <input type=text name=total size=10> </td> </tr>
And then make the changes in red in the JS part of the code;
Code:else { var princ = document.calc.loan.value; var term = document.calc.months.value; var intr = document.calc.rate.value / 1200; var pmt = princ * intr / (1  (Math.pow(1/(1 + intr), term))); document.calc.pay.value = pmt.toFixed(2) document.calc.total.value = ( term * pmt ).toFixed(2); }
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.