<script
language="javascript"
type="text/javascript">
var
princ;
var
ratepc;
var
years;
var
rate;
var
power;
function
calcAmt(frm)
{
princ
=
eval(frm.pr.value);
ratepc
=
eval(frm.rt.value);
years
=
eval(frm.yr.value);
rate
=
ratepc /
100;
power
=
Math.pow((1
+
rate),
years);
frm.amt.value
=
Math.round(princ
*
power *
100)
/
100;
frm.inter.value
=
Math.round((frm.amt.value
-
princ)
*
100)
/
100;
}
function
checkInput(frm)
{
if
(rate
==
0
||
rate >
.3)
{
window.alert
("Are
you sure that the interest rate is "
+
ratepc +"%?");
frm.rt.focus();
}
if
(years
==
0
||
years >
30)
{
window.alert
("Are
you sure that the term is "
+
years +
" years?");
frm.yr.focus();
}
}
</script>
<form
method=get
name=frm>
Principal
<input
type=text
name=pr
size=10
maxlength=10
onChange=calcAmt(this.form)>
Rate
<input
type=text
name=rt
size=6
maxlength=6
onChange=calcAmt(this.form)>
Years
<input
type=text
name=yr
size=5
maxlength=5
onChange=calcAmt(this.form)>
<br>
<br>
<input
type=button
name=calc
value="Calculate"
size=10
onClick=checkInput(this.form);
calcAmt(this.form);>
<input
type=reset
value="Clear">
<br>
<br>
Amount
<input
type=text
name=amt
size=10>
Interest
<input
type=text
name=inter
size=10>
</form>