<!-- jsset2_2b.html -->
<html>
<head>
<title>jsset2_2b.html - Calculate Loan Enhanced</title>
<style type="text/css">
body {
background-color: #000000;
color: #FFFFFF;
font-size: 30;
text-align: center;
}
</style>
<script type="text/javascript">
function calculate()
{
var amount, repayment, interest, total_interest, month_interest, term_loan, rate;
if (document.frmcalculateloan.txtloan.value == "")
{
alert("Please enter your loan amount");
document.frmcalculateloan.txtloan.focus();
}
else if (document.frmcalculateloan.txtloan.value != parseFloat(document.frmcalculateloan.txtloan.value))
{
alert("Your loan amount must be a number");
document.frmcalculateloan.txtloan.focus();
}
else if (document.frmcalculateloan.txtmonthly.value == "")
{
alert("Please enter your monthly loan repayment");
document.frmcalculateloan.txtmonthly.focus();
}
else if (document.frmcalculateloan.txtmonthly.value != parseFloat(document.frmcalculateloan.txtmonthly.value))
{
alert("Your monthly loan repayment must be a number");
document.frmcalculateloan.txtmonthly.focus();
}
else if (document.frmcalculateloan.txtint_rate.value == "")
{
alert("Please enter your interest rate");
document.frmcalculateloan.txtint_rate.focus();
}
else if (document.frmcalculateloan.txtint_rate.value != parseFloat(document.frmcalculateloan.txtint_rate.value))
{
alert("Your interest rate must be a number");
document.frmcalculateloan.txtint_rate.focus();
}
term_loan = 0;
total_interest = 0;
amount = parseFloat(document.frmcalculateloan.txtloan.value);
repayment = parseFloat(document.frmcalculateloan.txtmonthly.value);
rate = parseFloat(document.frmcalculateloan.txtint_rate.value);
if (repayment < rate)
{}
else
{
while (amount > 0)
{
if (repayment < amount)
{
amount = amount - repayment;
month_interest = (amount * (rate / 100) / 12);
total_interest = total_interest + month_interest;
amount = amount + month_interest;
}
else
{
amount = 0;
}
term_loan = term_loan + 1;
}
document.frmcalculateloan.readonly_term.value = parseInt(term_loan/12) + " years and " + (term_loan % 12) + " months";
document.frmcalculateloan.readonly_total_interest.value = "$" + total_interest.toFixed(2);
}
}
function clean()
{
//alert("in clean");
document.frmcalculateloan.txtloan.value = "";
document.frmcalculateloan.txtmonthly.value = "";
document.frmcalculateloan.txtint_rate.value = "";
document.frmcalculateloan.txtloan.value = "";
document.frmcalculateloan.readonly_term.value = "";
document.frmcalculateloan.readonly_total_interest.value = "";
document.frmcalculateloan.txtloan.focus();
document.frmcalculateloan.txtmonthly.focus();
document.frmcalculateloan.txtloan.focus();
document.frmcalculateloan.txtLoanAmount.focus();
}
</script>
</head>
<body onload="window.document.frmcalculateloan.txtloan.focus()">
<h1>Jsset2_2b - Calculate Loan Enhanced</h1>
<form name="frmcalculateloan">
Enter the Loan Amount : $<input type="text" name="txtloan" class="txtbox" /><br /><br />
Enter the Monthly Loan Repayment : $<input type="text" name="txtmonthly" class="txtbox" /><br /><br />
Enter the Interest Rate : <input type="text" name="txtint_rate" class="txtbox" /> %
<br /><br /><br />
<hr>
Term Of Loan: <input type="text" name="readonly_term" id="readonly_term" disabled="READONLY" class="READONLY" />
<br /><br />
Total Interest Paid: <input type="text" name="readonly_total_interest" id="readonly_total_interest" disabled="READONLY" class="disabled" />
</form>
<br /> <br />
<input type="button" name="cmdcalculate" value="Calculate term of loan and total interest" onclick="calculate()" />
<input type="button" name="cmdClear" value="Reset" onClick="clean()">
</body>
</html>
Everything works fine except i want it so if the user clicks the "calculate term of loan and total interest" button it doesn't display anything in the disabled textboxes. How would i do this? I've been stuck for hours.:P


Sign In
Create Account


Back to top









