/    Sign up×
Community /Pin to ProfileBookmark

Does anyone know how to do this

If you visit the following [B][URL=”http://tinyurl.com/ytc55b”]url[/URL][/B] (u:admin p:mosaic1) you will see a mortgage calculator. I want to have the figure 5.1 in the Interest Rate field when a user visits the page, then if they want they can change it to whatever figure they like…

here is my code:

[code=php]<?php

// 52 – Weekly
// 26 – Biweekly
// 12 – Monthly
// 6 – Bimonthly

$period = 12;

function calculateMortgage($balance,$rate,$term){
global $period;

$N = $term * $period;
$I = ($rate/100)/$period;
$v = pow((1+$I),$N);
$t = ($I*$v)/($v-1);
$result = $balance*$t;

return $result;
}

$balance = isset($_POST[‘balance’]) ? $_POST[‘balance’] : ”;
$rate = isset($_POST[‘rate’]) ? $_POST[‘rate’] : ”;
$term = isset($_POST[‘term’]) ? $_POST[‘term’] : ”;

?>[/code]

[code=php] <div id=”main_calc”><!– calc start –>

<div class=”caption1″>Mortgage Repayment Calculator</div>

<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”post” >
<table width=”345px” class=”calc_form”>
<tr>
<td>Loan Balance:</td>
<td><input class=”text” name=”balance” type=”text” size=”15″ value=”<?php echo $balance; ?>” /> €</td>
</tr>
<tr>
<td>Interest Rate:</td>
<td><input class=”text” name=”rate” type=”text” size=”5″ value=”<?php echo $rate; ?>” />
%</td>
</tr>
<tr>
<td>Loan Term:</td>
<td><input class=”text” name=”term” type=”text” size=”5″ value=”<?php echo $term; ?>” />
years</td>
</tr>
<tr>
<td></td>
<td align=”left”><br/>
<input class=”text” type=”submit” name=”submitBtn” value=”Calculate” /></td>
</tr>
</table>
</form>

<?php
if ((isset($_POST[‘submitBtn’]) && ($balance != ”) && ($rate != ”) && ($term != ”))){

?>
<div class=”caption2″>Result</div>

<div id=”result”>
<table width=”345px”>
<?php
$pay = round(calculateMortgage($balance,$rate,$term),2);
echo “<tr><td class=’res_heading’>Monthly Payment:</td><td class=’res’> €”.$pay.”</td></tr>”;
echo “<tr><td class=’res_heading’>Total Interest:</td><td class=’int’> €”.(($term*$pay*$period)-$balance).”</td></tr>”;
?>
</table>
<?php
echo “<br/><br/>”;
echo “<table class=’detail’>”;
echo “<tr><td>Month</td><td>Principial</td><td>Interest</td><td>Payment</td></tr>”;
for ($i=0;$i<($term*$period);$i++){
$tmp = (($pay) – ($balance*($rate/100/$period)));
$diff = round($tmp,2);
$int = round(($balance*$rate/100/$period),2);
$princ = $balance – $diff;
$balance = round($balance,0);
echo “<tr><td>$i. month</td><td> $”.number_format($balance).”</td><td> $”.number_format($int).”</td><td> $”.number_format($pay).”</td></tr>”;
$balance = $princ;
}
echo “</table>”;
?>
</div>
<?php
}
?>

</div> <!– calc end –>[/code]

Is this possible to do, if so does anyone know how, thanks in advance

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@scragarApr 01.2008 — [code=php] <td><input class="text" name="rate" type="text" size="5" value="<?php echo empty($rate)?'5.1':$rate; ?>" />[/code]
Copy linkTweet thisAlerts:
@oo7mlauthorApr 01.2008 — Cool, thanks a million
×

Success!

Help @oo7ml 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.18,
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,
)...