Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Mortgage Calculator Problem

Posted on 2004-04-01
3
Medium Priority
?
295 Views
Last Modified: 2013-12-03
My code is below - I thought it was ok, but I'm getting an error.  The error is this:

Line: 12  (I believe it is this - var mi = document.temps.IR.value / 1200;)
Char: 3

Error: 'document.temps.IR' is null or not an object
Code: 0

*****************************************************************
Code:

 <html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  <title>Mortgage Calculator</title>
  <script LANGUAGE="JavaScript">
function floor(number)
  {
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
  }
function dosum()
  {
  var mi = document.temps.IR.value / 1200;
  var base = 1;
  var mbase = 1 + mi;
  for (i=0; i<document.temps.YR.value * 12; i++)
  {
  base = base * mbase
  }
  document.temps.PI.value = floor(document.temps.LA.value * mi / ( 1 - (1/base)))
  document.temps.MT.value = floor(document.temps.AT.value / 12)
  document.temps.MI.value = floor(document.temps.AI.value / 12)
  var dasum = document.temps.LA.value * mi / ( 1 - (1/base)) +
  document.temps.AT.value / 12 +
  document.temps.AI.value / 12;
  document.temps.MP.value = floor(dasum);
  }
</script>
 
</head>
<body bgcolor="#FFFFFF">

<table width="71%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="100%"  border="0" cellspacing="2" cellpadding="2">
      <tr>
        <td colspan="6">Mortgage and Expense Information</td>
        </tr>
      <tr>
        <td colspan="6"><hr width="100%" size=1 noshade></td>
        </tr>
      <tr>
        <td width="15%"><font size="2"
  face="Arial, Verdana" color="003366">Term (Yrs.):</font></td>
        <td width="14%"><font size="2"
  face="Arial, Verdana" color="003366">
          <input name="YR"
  onChange="dosum()" size="6" value="25">
        </font></td>
        <td width="18%"><font size="2"
  face="Arial, Verdana" color="003366">Interest Rate:</font></td>
        <td width="18%"><font size="2"
  face="Arial, Verdana" color="003366">
          <input type="TEXT"
  name="IR" onChange="dosum()" size="6" value="8.0">
        </font></td>
        <td width="18%"><font color="003366" size="2" face="Arial, Verdana">Loan Amount: </font></td>
        <td width="17%"><font size="2"
  face="Arial, Verdana" color="003366">
          <input type="TEXT"
  name="LA" onChange="dosum()" size="7" value="100000">
        </font></td>
      </tr>
      <tr>
        <td><font size="2"
  face="Arial, Verdana" color="003366">Annual Taxes:</font></td>
        <td><font size="2"
  face="Arial, Verdana" color="003366">
          <input name="AT"
  onChange="dosum()" size="6" value="1500">
        </font></td>
        <td><font size="2"
  face="Arial, Verdana" color="003366">Annual Insurance:</font></td>
        <td><font size="2"
  face="Arial, Verdana" color="003366">
          <input name="AI"
  onChange="dosum()" size="6" value="500">
        </font></td>
        <td colspan="2"><font
  size="2" face="Arial, Verdana" color="003366">
          <input name="button"
  type="button" onClick="dosum()" value="Calculate Now!">
        </font></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%"  border="0" cellspacing="2" cellpadding="2">
      <tr>
        <td>Resulting Payments</td>
      </tr>
      <tr>
        <td><hr width="100%" size=1 noshade></td>
      </tr>
      <tr>
        <td><table width="100%"  border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td width="56%"><font size="2" face="Arial, Verdana" color="003366">Monthly Principal and Interest</font></td>
            <td width="44%"><font size="2" face="Arial, Verdana" color="003366">
              <input
  name="PI" size="10">
            </font></td>
          </tr>
          <tr>
            <td><font size="2" face="Arial, Verdana" color="003366">Monthly Taxes</font></td>
            <td><font size="2" face="Arial, Verdana" color="003366">
              <input
  type="TEXT" name="MT" size="10">
            </font></td>
          </tr>
          <tr>
            <td><font size="2" face="Arial, Verdana" color="003366">Monthly Insurance</font></td>
            <td><font size="2" face="Arial, Verdana" color="003366">
              <input
  type="TEXT" name="MI" size="10">
            </font></td>
          </tr>
          <tr>
            <td><strong><font size="2"
  face="Arial, Verdana" color="003366">Total Payment</font></strong></td>
            <td><strong><font size="2"
  face="Arial, Verdana" color="003366">
            <input
  type="TEXT" name="MP" size="10">
</font></strong></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><hr width="100%" size=1 noshade></td>
      </tr>
      <tr>
        <td><font size="-2" face="Arial, Verdana" color="003366">&nbsp;This information is accurate but may not apply to your actual mortgage agreement.&nbsp; Consult a professional Realtor or Mortgage Company for a written quote. </font></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
  </html>
*************************************************************************

Can anybody help?
0
Comment
Question by:velcrobots
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 1000 total points
ID: 10737499
Hi velcrobots,

Include the form name before the table as
<form name="temps">
<table>
.
.
.
</table>
</form>

Cheers!
venkat.
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 10737505
Not quite sure what "temps" is. I replaced it with a form and it works.

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  <title>Mortgage Calculator</title>
  <script LANGUAGE="JavaScript">
function floor(number)
  {
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
  }
function dosum()
  {
  var mi = document.forms[0].IR.value / 1200;
  var base = 1;
  var mbase = 1 + mi;
  for (i=0; i<document.forms[0].YR.value * 12; i++)
  {
  base = base * mbase
  }
  document.forms[0].PI.value = floor(document.forms[0].LA.value * mi / ( 1 - (1/base)))
  document.forms[0].MT.value = floor(document.forms[0].AT.value / 12)
  document.forms[0].MI.value = floor(document.forms[0].AI.value / 12)
  var dasum = document.forms[0].LA.value * mi / ( 1 - (1/base)) +
  document.forms[0].AT.value / 12 +
  document.forms[0].AI.value / 12;
  document.forms[0].MP.value = floor(dasum);
  }
</script>
 
</head>
<body bgcolor="#FFFFFF">
<form>
<table width="71%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="100%"  border="0" cellspacing="2" cellpadding="2">
      <tr>
        <td colspan="6">Mortgage and Expense Information</td>
        </tr>
      <tr>
        <td colspan="6"><hr width="100%" size=1 noshade></td>
        </tr>
      <tr>
        <td width="15%"><font size="2"
  face="Arial, Verdana" color="003366">Term (Yrs.):</font></td>
        <td width="14%"><font size="2"
  face="Arial, Verdana" color="003366">
          <input name="YR"
  onChange="dosum()" size="6" value="25">
        </font></td>
        <td width="18%"><font size="2"
  face="Arial, Verdana" color="003366">Interest Rate:</font></td>
        <td width="18%"><font size="2"
  face="Arial, Verdana" color="003366">
          <input type="TEXT"
  name="IR" onChange="dosum()" size="6" value="8.0">
        </font></td>
        <td width="18%"><font color="003366" size="2" face="Arial, Verdana">Loan Amount: </font></td>
        <td width="17%"><font size="2"
  face="Arial, Verdana" color="003366">
          <input type="TEXT"
  name="LA" onChange="dosum()" size="7" value="100000">
        </font></td>
      </tr>
      <tr>
        <td><font size="2"
  face="Arial, Verdana" color="003366">Annual Taxes:</font></td>
        <td><font size="2"
  face="Arial, Verdana" color="003366">
          <input name="AT"
  onChange="dosum()" size="6" value="1500">
        </font></td>
        <td><font size="2"
  face="Arial, Verdana" color="003366">Annual Insurance:</font></td>
        <td><font size="2"
  face="Arial, Verdana" color="003366">
          <input name="AI"
  onChange="dosum()" size="6" value="500">
        </font></td>
        <td colspan="2"><font
  size="2" face="Arial, Verdana" color="003366">
          <input name="button"
  type="button" onClick="dosum()" value="Calculate Now!">
        </font></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%"  border="0" cellspacing="2" cellpadding="2">
      <tr>
        <td>Resulting Payments</td>
      </tr>
      <tr>
        <td><hr width="100%" size=1 noshade></td>
      </tr>
      <tr>
        <td><table width="100%"  border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td width="56%"><font size="2" face="Arial, Verdana" color="003366">Monthly Principal and Interest</font></td>
            <td width="44%"><font size="2" face="Arial, Verdana" color="003366">
              <input
  name="PI" size="10">
            </font></td>
          </tr>
          <tr>
            <td><font size="2" face="Arial, Verdana" color="003366">Monthly Taxes</font></td>
            <td><font size="2" face="Arial, Verdana" color="003366">
              <input
  type="TEXT" name="MT" size="10">
            </font></td>
          </tr>
          <tr>
            <td><font size="2" face="Arial, Verdana" color="003366">Monthly Insurance</font></td>
            <td><font size="2" face="Arial, Verdana" color="003366">
              <input
  type="TEXT" name="MI" size="10">
            </font></td>
          </tr>
          <tr>
            <td><strong><font size="2"
  face="Arial, Verdana" color="003366">Total Payment</font></strong></td>
            <td><strong><font size="2"
  face="Arial, Verdana" color="003366">
            <input
  type="TEXT" name="MP" size="10">
</font></strong></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><hr width="100%" size=1 noshade></td>
      </tr>
      <tr>
        <td><font size="-2" face="Arial, Verdana" color="003366">&nbsp;This information is accurate but may not apply to your actual mortgage agreement.&nbsp; Consult a professional Realtor or Mortgage Company for a written quote. </font></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>
</body>
  </html>
0
 

Author Comment

by:velcrobots
ID: 10737651
Thank you both for the quick response, it works just perfectly now.  I had to give the points to vankat, he was just a couple minutes earlier!!!

Thanks again!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question