Ok, so I got a mortgage calculator script here: [url]http://hscripts.com/scripts/JavaScript/loan-calculator.php
…but I need help switching the “year term” area to a radio-group for just 15 or 30 years.
[B][I]Needless to say, JavaScript and I don’t exactly get along.
Here is my code (including the coded-out text field that actually worked and my new radio buttons that don’t…
[code=html]<script type=”text/javascript”>
function checnum(as)
{
var dd = as.value;
if(isNaN(dd))
{
dd = dd.substring(0,(dd.length-1));
as.value = dd;
}
}
function loan()
{
var a = document.first.aa.value;
var b = document.first.bb.value;
if (document.first.cc[1].checked){
var c = document.orderform.cc[1].value;
}else{
var c = document.orderform.cc[0].value;
}
//var c = document.first.cc.value;
var n = c * 12;
var r = b/(12*100);
var p = (a * r *Math.pow((1+r),n))/(Math.pow((1+r),n)-1);
var prin = Math.round(p*100)/100;
document.first.r1.value = prin;
var mon = Math.round(((n * prin) – a)*100)/100;
document.first.r2.value = mon;
var tot = Math.round((mon/n)*100)/100;
document.first.r3.value = tot;
for(var i=0;i<n;i++)
{
var z = a * r * 1;
var q = Math.round(z*100)/100;
var t = p – z;
var w = Math.round(t*100)/100;
var e = a-t;
var l = Math.round(e*100)/100;
a=e;
}
}
</script>
<form name=”first”>
<table class=subheading cellspacing=0 cellpadding=3>
<tr><td>Loan Amount:</td><td><input name=”aa” type=”text” size=”10″ onkeyup=”checnum(this)” ></td></tr>
<tr><td>Interest Rates:</td><td><input name=”bb” type=”text” size=”10″ onkeyup=”checnum(this)” ></td></tr>
<!–tr><td>Term(Years):</td><td><input name=”cc” type=”text” size=”10″ onkeyup=”checnum(this)”></td></tr–>
<tr><td>Term(Years):</td><td><label><input name=”cc” id=”cc2″ type=”radio” size=”10″ value=”15″ onkeyup=”checnum(this)”>15-Year</label><br/>
<label><input name=”cc” id=”cc2″ type=”radio” size=”10″ value=”30″ onkeyup=”checnum(this)”>30-Year</label>
</td></tr>
</table>
<br><input type=”button” name=”ss” value=”calculate” onclick=”loan()” class=”calc pretty”>
<br/>
Monthly Payment(EMI):<br/>
<input name=”r1″ type=”text” readonly />
(BTW, guys, I love the new look of the site)