Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts

    mortgage calculator

    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...

    this is the form:
    Code:
    <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 Code:
    <?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
    Last edited by harlequin2k5; 08-02-2007 at 03:57 AM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    It appears you posted the same snippet twice.

  • #3
    Regular Coder harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Thumbs up got it!

    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 Code:
    <?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.";
        }
        }
        

    ?>

  • #4
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    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.
    Leonard Whistler

  • #5
    Regular Coder harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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.";
        }
        }
        

    ?>

  • #6
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by harlequin2k5 View Post
    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.
    Leonard Whistler

  • #7
    New Coder
    Join Date
    Apr 2007
    Location
    India
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mortgage calculations

    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.
    GemGuy

    Be friend of me
    Hey what a fun

  • #8
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Quote Originally Posted by gemguy View Post
    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.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #10
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    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.
    Leonard Whistler

  • #11
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is an amazing AJAX mortgage calculator called mookal with all the bells and whistles. It requires no hits to the server, all calculations and plotting on the client, 100% javascript.

  • #12
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    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.

  • #13
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by venegal View Post
    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 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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •