...

View Full Version : mortgage calculator



harlequin2k5
08-02-2007, 04:27 AM
after searching for a mortgage calculator script and not liking what I found I decided it was high time to try to make my own - I don't need anything fancy...and I think I'm just being blind to what I'm missing - but nothing displays when I click on calculate

don't be too harsh if it's something dumb - I'm trying real hard to learn this stuff...:o

this is the form:

<form method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<p>Amount: <input type="text" name="amount" id="amount" /></p>
<p>Interest: <input type="text" name="interest" id="interest" /></p>
<p>Term: <input type="text" name="term" id="term" /></p>
<input type="submit" value="Calculate" name="calculate" />
</form>

this is what I'm trying to calculate:

<?php
//$amount=the total amount financed
//$interest=amount of interest to apply
//$percent=$interest/100
//$term=total years of loan
//$payment=(($amount*$percent)*$term)/($term*12)

$amount=$_POST['amount'];
$interest=$_POST['interest'];
$term=$_POST['term'];

if (isset($_GET['calculate']) && (floatval($amount) !=0) && (floatval($interest) !=0) && (floatval($term) !=0))
{
$percent=($interest/100);
$payment=(($amount*$percent)*$term)/($term*12);
echo "Monthly payment=$";
echo round($payment);
}

else
{
echo "Please complete all fields.";
}


?>

edit: they don't call me bimbo for nuttin *chuckles*...thanks for the catch fumi :)

Fumigator
08-02-2007, 04:54 AM
It appears you posted the same snippet twice.

harlequin2k5
08-02-2007, 05:35 AM
I knew I was missing something relatively easy...after adding error_reporting(e_all); an undefined index error popped up...

the corrected code is...

<?php

error_reporting(E_ALL);


//$amount=the total amount financed
//$interest=amount of interest to apply
//$percent=$interest/100
//$term=total years of loan
//$payment=(($amount*$percent)*$term)/($term*12)

if (isset($_GET['calculate']))

{

$amount=$_GET['amount'];
$interest=$_GET['interest'];
$term=$_GET['term'];

if ((floatval($amount) !=0) && (floatval($interest) !=0) && (floatval($term) !=0))
{
$percent=($interest/100);
$payment=(($amount*$percent)*$term)/($term*12);
echo "Monthly payment=$";
echo round($payment);
}

else
{
echo "Please complete all fields.";
}
}


?>

Len Whistler
08-02-2007, 07:17 AM
I would use Ajax/JavaScript for a mortgage calculator, then the output changes anytime a number is entered or changed without reloading the page. I played around with coding a JavaScript shopping cart and it really is nice having the total update in real time. When I get more time I'm going to work on it more and see how Ajax can improve it.

harlequin2k5
08-02-2007, 07:25 AM
len -
I thought about doing that but I have absolutely no experience with ajax and I have no skill with js

if the main site was providing the information I would have explored that but the listings are coming from a remote site

update: the previous corrected code was still missing something - I've finally gotten it to work correctly all around


<?php

error_reporting(E_ALL);


//$amount=the total amount financed
//$interest=amount of interest to apply
//$percent=$interest/100
//$term=total years of loan
//$payment=(($amount*$percent)*$term)/($term*12)

if (isset($_GET['calculate']))

{

$amount=$_GET['amount'];
$interest=$_GET['interest'];
$term=$_GET['term'];
$pow=pow((1+($interest/1200)), ($term*12));

if ((floatval($amount) !=0) && (floatval($interest) !=0) && (floatval($term) !=0))
{
$percent=($interest/100);
$months=($term*12);
$payment=($amount*$pow)*($interest/1200)/($pow-1);
echo "Amount to finance:$";
echo round($amount);
echo "<br />Interest rate: ";
echo round($interest);
echo "% <br />";
echo "Loan term: ";
echo round($term);
echo " years<br />";
echo "Monthly payment=$";
echo round($payment);
}

else
{
echo "Please complete all fields.";
}
}


?>

Len Whistler
08-02-2007, 07:30 AM
len -
I thought about doing that but I have absolutely no experience with ajax and I have no skill with js

Same with me....That's why I never completed the script, JavaScript is a pain compared to PHP.

gemguy
08-03-2007, 06:41 AM
Hi,

Its better to do the calculator by using javascript i think so.. Ok. fine. have a look at this site for any calculating doubts

http://easycalculation.com/mortgage/mortgage.php

It founds to be very easy and best for calculating the loans etc.

StupidRalph
08-03-2007, 06:54 AM
Hi,

Its better to do the calculator by using javascript i think so.. Ok. fine. have a look at this site for any calculating doubts

http://easycalculation.com/mortgage/mortgage.php

It founds to be very easy and best for calculating the loans etc.

Its great as far as the user's experience goes, but I think you should still validate things on the server-side. Therefore, I'd do both personally. The javascript needed for this wouldn't be that complex.

felgall
08-03-2007, 07:28 AM
Unless you need to look up something on the server or want to make sure it works with JavaScript disabled, a server side solution is unnecessary.

A mortgage calculator doesn't need to look anything up and so a pure JavaScript solution without Ajax gives the fastest response for users who have JavaScript enabled. A pure server side solution that is disabled via javaScript would provide a slower solution for those without JavaScript.

Len Whistler
08-05-2007, 01:10 AM
I decided to have a go at a Javascript mortgage rate calculator and below is a link to what I have so far. It's about 90% complete.

http://www.rgbpixels.ca/mortgage_rate_calculator

What I really like about a Javascript calculator over a PHP calculator is that you do not have to re-load the page or click on a submit button to update the output. Output is updated as you change the numbers.

topcoder1
06-09-2009, 03:46 AM
Here is an amazing AJAX mortgage calculator (http://www.mookal.com) called mookal with all the bells and whistles. It requires no hits to the server, all calculations and plotting on the client, 100% javascript.

venegal
06-09-2009, 04:07 AM
How is it ajax, when it isn't hitting the server?
And I'm pretty sure that one wasn't around when that thread was active two years ago.

topcoder1
06-09-2009, 04:33 AM
How is it ajax, when it isn't hitting the server?
And I'm pretty sure that one wasn't around when that thread was active two years ago.
as quoted from wiki:
Like DHTML and LAMP, Ajax is not a technology in itself, but a term that refers to the use of a group of technologies. Ajax uses a combination of:

* HTML and CSS for marking up and styling information.
* The DOM accessed with JavaScript to dynamically display and interact with the information presented.
* A method for exchanging data asynchronously between browser and server, therewith avoiding page reloads. The XMLHttpRequest (XHR) object is usually used, but sometimes an IFrame object or a dynamically added <script> tag is used instead.
* A format for the data sent to the browser. Common formats include XML, pre-formatted HTML, plain text, and JSON. This data could be created dynamically by some form of server-side scripting.

So I guess since Mookal (http://www.mookal.com) is lacking in point 3 and 4, so technically I guess it's not ajax, any experts care to clarify? Let me rephrase it as a 100% Javascript application as oppose to a ajax application then if you want to be strict on the terminology.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum