/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Use radio button values instead of text values for a pre-made script…??

Ok, so I got a mortgage calculator script here: [url]http://hscripts.com/scripts/JavaScript/loan-calculator.php[/url]

…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.[/I][/B] If I could code this in PHP, it would be done and gone, but for some reason JavaScript is just more difficult for me.

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 />[/code]

(BTW, guys, I love the new look of the site)

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@amandaNHTauthorSep 06.2012 — Nevermind. All I had to do was change "orderform.cc" to "first.cc" in the part that sets the value... It was still "orderform." from the place I found the "how to do it" thing.
×

Success!

Help @amandaNHT spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...