这是我的编码,我正在努力计算汽车贷款的分期付款。但似乎我的计算按钮不起作用。我不知道我的错误是什么。如果有人能提供帮助那就太好了。 新手程序员在这里。
<table>
<tr><td> Car Price (RM): </td>
<td><input type = "text" name = "txtPrice" size = "10" onchange="calculate();"></td>
</tr>
<tr><td> (Retail Purchase Price) </td>
</tr>
<tr><td> Down Payment (RM): </td>
<td><input type = "text" name = "txtDownPayment" size = "10" onchange="calculate();"></td>
<td> (minimum of 10% of car price) </td>
</tr>
<tr><td> Interest Rate (%): </td>
<td><input type = "text" name = "txtInterest" size = "10" onchange="calculate();"></td>
</tr>
<tr><td> Loan Duration: </td>
<td><input type = "text" name = "txtDuration" size = "5" onchange="calculate();"></td>
<td> (year) </td>
</tr>
</table>
<br>
<table>
<tr><td><input type = "button" value = "Calculate" onClick = "calculate();"></td>
<td> RM </td>
<td><input type = "text" name = "txtLoanInstallment" size = "10"></td>
</tr>
</table>
<script language = "JavaScript">
function calculate()
{
var price, downPayment, interest, duration, tenPercent, loan, totalLoan;
price = parseDouble (document.form1.txtPrice.value);
downPayment = parseDouble (document.form1.txtDownPayment.value);
interest = parseDouble (document.form1.txtInterest.value);
duration = parseInt (document.form1.txtDuration.value);
tenPercent = (downPayment/price * 10);
loan = price - tenPercent;
totalLoan = (loan + (loan * interest*0.01) * duration) / (duration * 12);
document.form1.txtLoanInstallment.value = totalLoan.toFixed(2);
}
</script>