Basically Im trying to make a loans calculator that will display the following in a new window;
I have based my coding from the following link...
http://www.java2s.com/Code/JavaScript/Form-Control/JavaScriptLoanCalculator.htm
I've tried everything I can think of through looking at tutorials and what not... but it just doesnt work.
Anyone can lend a favour and push me in the right direction?
many thanks, dave
- Your interest rate is charged at...
- Your monthly payment is £
- The total interest paid at the end of the loan will be £
I have based my coding from the following link...
http://www.java2s.com/Code/JavaScript/Form-Control/JavaScriptLoanCalculator.htm
I've tried everything I can think of through looking at tutorials and what not... but it just doesnt work.
Anyone can lend a favour and push me in the right direction?
many thanks, dave
Code:
<head><title> Loan Calculator</title></head>
<body>
<center><h1>Welcome to the Loan Calculator</h1></center>
<br>
<p><h4><center>This web page will allow you to calculate the interest rate.</center></h4></p>
<h4><center>Follow the steps below to calculate the interest on the loan you have taken out.</center></h4>
<br>
<center>
<style type="text/css">
<!--
body{ font-family: Verdana, Arial, Helvetica, sans-serif;
color: #003366;
}
body {
background-color: #62B0FF;
}
-->
</style>
<form name="loandata">
<table>
<tr><td colspan="3"><b>Enter Loan Information:</b></td></tr>
<tr>
<td>1)</td>
<td>Amount of the loan:</td>
<td><input type="text" name="amount" size="12"
onchange="calculate();"></td>
</tr>
<tr>
<td>2)</td>
<td>Monthly percentage rate of interest:</td>
<td><input type="text" name="interest" size="12"
onchange="calculate();"></td>
</td>
</tr>
<tr>
<td>3)</td>
<td>Repayment period in years:</td>
<td><input type="text" name="years" size="12"
onchange="calculate();"></td>
</tr>
<tr><td colspan="3">
<input type="Submit" value="calculate" onclick="calculate()" >
</td></tr>
<tr><td colspan="3">
</table>
</form>
</center>
</body>
<script language="JavaScript">
function calculate()
{
var amount = document.loandata.amount.value;
var interest = document.loandata.interest.value / 100 / 12;
var payments = document.loandata.years.value * 12;
var x=Math.pow((1+i),(-payments));
var y=1-x;
var z=amount*(i/y);
newWin=window.open ('','NewWindow', 'width=500,height=400');
newWin.document.write("</br>" + "<b>Your monthly payment is £</b>" + sterling + "</br>");
newWin.document.write("</br>" + "<b>Your interest rate is charged at </b>" + finalinterest() +"%" + " over " + (payments) + " months" + "</br>");
newWin.document.write("</br>" + "<b>The total interest paid at the end of the loan will be £</b>" + sterling (((z * payments)-amount)));
newWin.document.close(); " >
</script>
<script language="JavaScript" type="text/javascript">
function finalinterest()
{
if (loandata.amount.value <=4000)
{
i=9.9
}
else if ((loandata.amount.value >4000) && (loandata.amount.value<=10000))
{
i=7.9
}
else if ((loandata.amount.value >10000) && (loandata.amount.value<=14000))
{
i=5.9
}
else if ((loandata.amount.value >14000) && (loandata.amount.value<=20000))
{
i=4.9
}
else if (loandata.amount.value>=20000)
{
i=4.0
}
return i;
}
</script>
</html>