/    Sign up×
Community /Pin to ProfileBookmark

My calculator is not returning correct code.

I’ve made a Mortgage calculator that is supposed to calculate monthly payments and the amount of total payments when data is entered. I’ve set the form up, but everytime I click on Calculate, the form clears and does not list the answers in the two bottom windows. Here is my work, how can it be corrected to work?

<html>
<head>
<title>Mortgage Calculator</title>
<body>
<h1 align=”center”><b>Mortgage Calculator</b></h1>
<hr align=”center” size=”6″ width=”75%”>
<p> Enter the yearly interest rate as a decimal (e.g., 8.5%=0.085), the total number of monthly

payments and the amount of the mortgage. Click on the “Calculate” button to view the monthly

payment. Click on the “Reset” button to reset the form.</p>

<hr align=”center” size=”3″ width=”100%”>

<body>

<style>
.numbers {text-align:right; background-color:lightyellow}
.fmlabel {color:black}
</style>

<script>

function dollars(n) {
n=eval(n);
n=Math.round(n*100)/100;
return (n == Math.round(n)) ? n += “.00” : (n*
10 == Math.round(n*10)) ? n +=”0″ : n;
}

function Monthly(I,N,S) {
// I=yearly interest rate;
// N=number of monthly payments;
// S=loan amount;
return (S*I/12*Math.pow(I/12+1,N))/(Math.pow(I/12+1,N)-1);
}

function ShowVal() {
I=eval(document.mortgage.I.value);
N=eval(document.mortgage.N.value);
S=eval(document.mortgage.S.value);
document.mortgage.Payment.value=dollars(Monthly());
document.mortgage.Total.value=dollars(Monthly()*N);
}

</script>
</head>
<table width=”520″ valign=”top” align=”center” colspan=”2″>
<tr>
<!– Start Calculator Form –>
<form name=”mortgage” method=”post” onsubmit=”return ShowVal()” onreset=”location.reload()”>
<td valign=”top”>
<span class=”fmlabel”>Loan Amount:</span>
</td>
<td valign=”top” colspan=”2″ align=”right”>
<input class=”numbers” name=”S” size=”40″ value=””>
</td>
</tr>
<tr>
<td valign=”top”>
<span class=”fmlabel”>Yearly interest rates:</span>
</td>
<td valign=”top” colspan=”2″ align=”right”>
<input class=”numbers” name=”I” size=”40″ value=””>
</td>
</tr>
<tr>
<td valign=”top”>
<span class=”fmlabel”>Total Number of Monthly Payments:</span>
</td>
<td valign=”top” colspan=”2″ align=”right”>
<input class=”numbers” name=”N” size=”40″ value=””>
</td>
</tr>
<tr>
<!– BUTTONS TO CALCULATE OR RESET FORM –>
<td align=”center” colspan=”2″>
<input type=”submit” value=”Calculate”>
&nbsp;&nbsp;
<input type=”reset” value=”Reset”>
</td>
</tr>
</table>
<hr align=”center” size=”3″ width=”100%” color=”black”>

<table width=”520″ valign=”top” align=”center” colspan=”2″>
<tr>
<td valign=”top”>
<span class=”fmlabel”>Monthly Payment:</span>
</td>
<td valign=”top” colspan=”2″ align=”right”>
<input class=”numbers” name=”Payment” size=”40″ value=”0.00″ disabled>
</td>
</tr>
<tr>
<td valign=”top”>
<span class=”fmlabel”>Total Payments:</span>
</td>
<td valign=”top” colspan=”2″ align=”right”>
<input class=”numbers” name=”Total” size=”40″ value=”0.00″ disabled>
</td>
</tr>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERNov 25.2007 — I think most of your problems are here:
[code=php]
function ShowVal() {
I=eval(document.mortgage.I.value);
N=eval(document.mortgage.N.value);
S=eval(document.mortgage.S.value);
M = Monthly(I,N,S);
document.mortgage.Payment.value=dollars(M);
document.mortgage.Total.value=dollars(M*N);
// alert(I+'n'+N+'n'+S+'n'+document.mortgage.Payment.value+'n'+document.mortgage.Total.value);
return false;
}
[/code]

But I haven't check the results for accuracy. :o

Needed to pass the information to the 'ShowVal' function.

Can also use this if you like:
[code=php]
function dollars(n) {
return n.toFixed(2);
}
[/code]
×

Success!

Help @Mariko1222 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.16,
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,
)...