Mortgage Calculator

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Mortgage Calculator

Post by fractalvibes »

Before I try and reinvent the wheel, does anyone know where there is a code download for a Mortgage Calculator? PHP or ASP or Javascript would work for me. Plenty of sites have them, don't know of any that allow hot-linking or deep linking from form posts on a different site. Surely there are some floating around out there...

Any hints most appreciated!

Phil J.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

do you mean morgage? if so i have a basic javascript calculator page i can give you. then you can modify that to your needs, and for this, you should use javascript, no reason to busy your server with the extraworkload when the person's computer can do it
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

That would be excellent, I'd like to take a look at it. The spelling here is
mortgage, mortgagee, etc. i.e. a home loan.

thanks!
Phil J.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

Code: Select all

<html>
   <head>
      <title>interest calculator</title>

   </head>
   <body>
   <p><h1>This is the earning calculator assignment. It forgoes some things such as compounding interest. It also calculates only by full year.</h1>
   <!-- this is a list of instructions on use -->
   <p>

      <nl>Instructions on use of Calculator
         <li>write yearly deposit amount<sup><font size=-1>1</font></sup> in text field marked "Deposit Amt."
         <li>write yearly intrest rate<sup><font size=-1>2</font></sup> in feild marked "Interest Rate"
         <li>write number of years<sup><font size=-1>3</font></sup> you wish to leave it in the bank in field marked "Term"
         <li>leave the "Final Amount" field as is.
         <li>push the calculate button
      </nl>

   <!-- list of restrictions -->
   <br>1: must be a positive integer greater than or equal to 1 with no more than two decimal places.
   <br>2: must be between 0.00 and 20.00 inclusive. The default interest rate is 0%. this will be used if no interest rate is provided.
   <br>3: this can be as low as 1 year.
   <p>

   <!-- form with a table nested in it to give clarity and alignment -->
      <form name="intCalc">
         <table cell border=1 cell padding=%1>
            <tr>

               <td>if&nbsp;one&nbsp;places&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$</td>
               <td><input type=text name=deposit size=10 value="Deposit Amt.">
               <td>per year
            </tr><tr>
               <td>at&nbsp;an&nbsp;intrest&nbsp;rate&nbsp;of
               <td><input type=text name=intrest size=10 value="Interest Rate">

               <td>% per year
            </tr><tr>
               <td>for&nbsp;a&nbsp;total&nbsp;of
               <td><input type=text name=yrs size=10 value="Term">
               <td>years
            </tr><tr>
               <td>one&nbsp;will&nbsp;have&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$
               <td><input type=text name=amt size=10 value="Final Amount">

               <td>at the time of withdrawl
            </tr><tr>
               <td>
               <td align=center><input type=button value=calculate onClick=calculate()>
               <td>
            </tr>
         </table>
      </form>

   <!-- script that checks the variables and does the calculation -->

      <script language="JavaScript"> 
         function calculate()&#123;
            
            /* first grab the three variables that will be used */
            var dep=(document.intCalc.deposit.value *1);
            var rate=(document.intCalc.intrest.value *1);
            var length=(document.intCalc.yrs.value *1);
            var total=0;
            
            /* then check to make sure they are valid */
            if (dep==null)&#123; //check to make sure there's a deposit
               alert("Please enter a deposit amount.")&#125;;
            else if ((dep*100)<100)&#123; // if so make sure it's not too low
               alert("The yearly deposit is too low")&#125;;
            else if (((dep*100)-Math.round(dep*100))>0)&#123; // make sure there's no fractions of a penny
               alert("You can't deposit fractions of a penny")&#125;;
            // else if (b=="Interest Rate")&#123;
               alert("You forgot to negotiate an interest rate.")&#125;;
            else if (((rate*100)<0)||((rate*100)>2000))&#123; // make sure it is valid
               alert("The rate is invalid")&#125;;
               alert("You forgot to set a Term.")&#125;;
            else if (length==null)&#123; // check for the number of years they want it held
               alert("Please enter the number of years your money will be in the bank's possesion")&#125;;
            else if (length<1)&#123; // make sure it's at least a year
               alert("This bank will not hold onto your money for less than a year.")&#125;;
            else if ((length-Math.round(length))>0)&#123; // and that it's not got some weird fraction
               alert("That includes a fraction of a year please decide how many YEARS you would like it deposited for. We don't try to guess how you divided the year into decimal form.")&#125;;
            
            /* if all that is valid, then calculate the value */
            else &#123;rate=(rate/100)+1; //make the 1.x% so that when multiplied by the total it will yeild the result
            
            /* then calculate the amount... */
            for(i=0; i<length; i++)&#123;
               total=(total+dep)*rate;&#125;;
            
            /* ... and return it to the user */
            document.intCalc.amt.value=Math.round(100*total)/100; //this makes sure there are only 2 decimal places.
         &#125;;&#125;
      </script>
   </body>
</html>

have fun!
Post Reply