codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  functions and calling them  shadow1100 at 05:10 on Friday, April 09, 2004
 

What am I doing wrong. I am trying to make a simple mortagage calcultor that on function calls on another. It is driving me nuts. thanks.<html>
<head>
<title>Mortgage Calculator</title>
<script>
<--to figure the monthly Payments-->
function Monthly(I,N,S) {
// I = yearly interest rate;
// N = number of monthly payments;
// S = loan amount;
return= (S*I/12*Math.pow(I/12+1,N))/Math.pow(I/12+1,N)-1);
}

function ShowVal(){
var S=eval(document.calc.S.value);
var N=eval(document.calc.N.value);
var I=eval(document.calc.I.value);
document.calc..MP.value=Monthly();
document.calc.TP.value=Monthly()*N;
}
</script>
</head>
<body>
<!--Start Form-->
<form name="Calc">
<table width="50%" align="center">
<center>
<tr>
<td>Loan Amount:</td>
<td><input type="text" id="S"id="S" size="8"></td>
</tr>
<tr>
<td>Yearly Interest Rate:</td>
<td><input type="text" id="I" name="I" size="8"></td>
</tr>
<tr>
<td>Total Number of Months:</td>
<td><input type="text" id="N" name="N" size="8"></td>
</tr>
<tr>
<td><input onClick="ShowVal()" type="button" value="Calculate"></td>
<td><input type="reset" Value="Reset"></td>
</tr>
</table>
<table>
<HR align="center" size="2" width="100%">
<tr>
<td>Monthly Payments:</td>
<td><input type="text" id="MP" name="MP" size="8"></td>
</tr>
<tr>
<td>Total Payments:</td>
<td><input type="text" id="TP" Name"TP" size="8"></td>
</tr>
</form>
</table>
</body>
</html>


  Re: functions and calling them  jackson17 at 14:42 on Wednesday, April 14, 2004
 

Hi there - try working from my script:

<SCRIPT LANGUAGE="JavaScript">
<!--
function checkForZero(field) {
if (field.value == 0 || field.value.length == 0) {
alert ("This field can't be 0!");
field.focus(); }
else
calculatePayment(field.form);
}

function cmdCalc_Click(form) {
if (form.price.value == 0 || form.price.value.length == 0) {
alert ("The Price field can't be 0!");
form.price.focus(); }
else if (form.ir.value == 0 || form.ir.value.length == 0) {
alert ("The Interest Rate field can't be 0!");
form.ir.focus(); }
else if (form.term.value == 0 || form.term.value.length == 0) {
alert ("The Term field can't be 0!");
form.term.focus(); }
else
calculatePayment(form);
}

function calculatePayment(form) {
princ = form.price.value - form.dp.value;
intRate = (form.ir.value/100) / 12;
months = form.term.value * 12;
form.pmt.value = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
form.principle.value = princ;
form.payments.value = months;
}
//-->
</SCRIPT>

If u have problems with it - just ask (jamiejay178@hotmail.com) - Good luck








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: onload event
•  Active Widgets
•  Re: onmouseover change image and text
•  Line Printer Interface
•  import contacts of msn/yahoo
•  Call windows apps from web apps
•  Re: ASP.NET web controls
•  netscape 6 browser problem
•  Re: Print .doc file from the website using System.Diagnostics.Process


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005