SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    0 Post(s)
    0 Thread(s)

    Help on Creating a Monthly Mortgage Calculator

    I am trying to create a monthly mortgage calculator, I have been able to make it show prompts for Amount of loan; Interest rate; and Term of loan (in months), but it will not display the results. Below is the code I have utilized to get this far. Any and all help will be appreciated.


    <title>Mortgage Payment Calculator</title>

    <body bgcolor=blue text=yellow>

    <!output the name, date, time header, with a horizontal line between this heading and the
    body of the web page>
    <script language="JavaScript">
    document.write('<center><h3>--David Brown--');
    myDate=new Date();

    <script type="text/javascript">

    loan=prompt("Amount of loan","");
    interest_rate=prompt("Annual interest rate (%)","");
    months=prompt("Term of loan (months)","");

    rate=interest_rate / 100 /12;
    payment=loan * (rate / (1- (1 / math.pow((1+ rate), months))));

    document.write("loan amount:",loan,"<br>");
    document.write("interest rate:",interest_rate,"% per annum","<br>");
    document.write("Term:", months,"months","<br>");
    document.write("Monthly payment:",payment);


  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Sydney, NSW, Australia
    25 Post(s)
    1 Thread(s)
    The first thing I suggest you do is to get rid of all the prompt() calls which are mainly intended for debugging and in some browsers have a disable JavaScript option at the bottom.

    I'd also suggest that you get rid of all the document.write statements and use one of innerHTML, the standard DOM calls, or a form in the web page itself instead.

    You should also change that language=JavaScript" reference to type="text/javascript".
    Stephen J Chapman, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

Tags for this Thread


Posting Permissions

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