SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    is craving 'the potato' slayerment's Avatar
    Join Date
    Nov 2002
    Location
    Scottsdale, Arizona, USA
    Posts
    603
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Q: Calculate Mortgage Payment

    I'm trying to create a mortgage payment calculator in Javascript and am having problems. My algorithm seems correct but it's not giving the right results. Im using this code:

    PHP Code:
    function do_calc_payment(){
    var 
    term document.calc_payment.term.value;
    var 
    rate document.calc_payment.rate.value;
    var 
    amount document.calc_payment.amount.value;
    var 
    rate / (12*100);
    var 
    term 12;
    var 
    payment amount * ( / (- (j) ^ -m))
    var 
    result "$"+Math.round((payment)*1000)/1000;
    if(
    isNaN(payment)){
    document.calc_payment.rate.value="";
    document.calc_payment.amount.value="";
    result="Not a Number";
    }
    if(
    payment.length>=15){
    result="Max Characters";
    }
    document.getElementById('new_payment').innerHTML result;

    Here's a link to the calculator: http://www.slayerment.com/calc.php

    Any help would be great! Thank you .

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The ^ operator in javascript is not for exponents (as I discovered yesterday)

    Use:
    result = Math.pow(base, exponent)
    instead

  3. #3
    is craving 'the potato' slayerment's Avatar
    Join Date
    Nov 2002
    Location
    Scottsdale, Arizona, USA
    Posts
    603
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet, that did it! Cheers


Bookmarks

Posting Permissions

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