Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page getting hung in Netscape

Status
Not open for further replies.

jimny

Technical User
Oct 18, 2002
52
0
0
US
I modified a mortgage calculator to amortize based on the starting month. The logic is fine and everything works nice in IE, but the algorythm gets hung in Netscape. Can anyone identify if one of the methods or functions is erroneous.

Whole code for the page is included...

<HTML>
<HEAD>
<TITLE>Loan Calculator</TITLE>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--

function RND2(n)
{
pennies = n * 100;
pennies = Math.round(pennies);
strPennies = &quot;&quot; + pennies;
len = strPennies.length;
return strPennies.substring(0, len - 2) + &quot;.&quot; + strPennies.substring(len - 2, len);
}

function Monthly(principal, years, apr)
{
rate = apr / 12;
payments = years * 12;
return RND2(principal * rate / (1 - (1 / Math.pow(1 + rate, payments))));
}

function Amortize(principal, years, apr, mon)
{
payments = years * 12;
monthlyInterest = apr / 12;
monthlyPayment = Monthly(principal, years, apr);

document.write(&quot;<HEAD><TITLE>AMORTIZED!!!</TITLE></HEAD>&quot;);

document.write(&quot;<style type='text/css'>td, th {font-family : Verdana, Arial, Helvetica;font-size : 9pt;font-style : normal}</style>&quot;);

document.write(&quot;<BODY>&quot;);
document.write(&quot;<TABLE BORDER=0 align=center>&quot;);

document.write(&quot;<TR><TD align=center colspan=4><H1>Amortization Table</H1></TD></TR>&quot;);
document.write(&quot;<TR><TD align=center colspan=4><HR></TD></TR>&quot;);



document.write(&quot;<TR>&quot;);
document.write(&quot;<TH COLSPAN=4>&quot;);
document.write(&quot;$&quot; + RND2(principal));
document.write(&quot; at &quot; + RND2(apr) + &quot;%&quot;);
document.write(&quot; over &quot; + years + &quot; years.<BR>&quot;);
document.write(&quot;Monthly payment: $&quot; + Monthly(principal, years, apr));
document.write(&quot;</TH>&quot;);
document.write(&quot;</TR>&quot;);

document.write(&quot;<TR>&quot;);
document.write(&quot;<TH></TH>&quot;);
document.write(&quot;<TH COLSPAN=2>Payment</TH>&quot;);
document.write(&quot;</TR>&quot;);

document.write(&quot;<TR>&quot;);
document.write(&quot;<TH>Month</TH>&quot;);
document.write(&quot;<TH>Interest</TH>&quot;);
document.write(&quot;<TH>Principal</TH>&quot;);
document.write(&quot;<TH>Balance</TH>&quot;);
document.write(&quot;</TR>&quot;);

var mnth = mon + 1;
var strMnth = &quot;&quot;;
var yr = 1;
var yrInt = 0;

for(i = 1; i <= payments; i++)
{

if (mnth == 1)
strMnth=&quot;January&quot;;
if (mnth == 2)
strMnth=&quot;February&quot;;
if (mnth == 3)
strMnth=&quot;March&quot;;
if (mnth == 4)
strMnth=&quot;April&quot;;
if (mnth == 5)
strMnth=&quot;May&quot;;
if (mnth == 6)
strMnth=&quot;June&quot;;
if (mnth == 7)
strMnth=&quot;July&quot;;
if (mnth == 8)
strMnth=&quot;August&quot;;
if (mnth == 9)
strMnth=&quot;September&quot;;
if (mnth == 10)
strMnth=&quot;October&quot;;
if (mnth == 11)
strMnth=&quot;November&quot;;
if (mnth == 12)
strMnth=&quot;December&quot;;
if (mnth > 12)
strMnth = i;

if ((i == 1) || (mnth == 1))
{
document.write(&quot;<TR><TD><B>YEAR &quot; + yr + &quot;</B></TD>&quot;);
document.write(&quot;<TD colspan=3>Total Interest Paid: $&quot; + RND2(yrInt) + &quot;</TD></TR>&quot;);
yrInt = 0;
}

document.write(&quot;<TR>&quot;);
document.write(&quot;<TD> &quot; + i + &quot; &quot; + strMnth + &quot; </TD>&quot;);

interestPayment = principal * monthlyInterest;
yrInt = yrInt + interestPayment;
document.write(&quot;<TD> $&quot; + RND2(interestPayment) + &quot; </TD>&quot;);

principalPayment = monthlyPayment - interestPayment;
document.write(&quot;<TD> $&quot; + RND2(principalPayment) + &quot; </TD>&quot;);

principal -= principalPayment;
document.write(&quot;<TD> $&quot; + RND2(principal) + &quot; </TD>&quot;);

document.write(&quot;</TR>&quot;);



if (mnth <= 12)
{
mnth = mnth + 1;
}
if (mnth > 12)
{
mnth = 1;
yr = yr + 1;
}

}

document.write(&quot;</TABLE>&quot;);

document.write(&quot;</BODY>&quot;);


}


function calculate(principal, years, apr, mon)
{
payments = years * 12;
monthlyInterest = apr / 12;
monthlyPayment = Monthly(principal, years, apr);

document.form.Total.value = RND2(monthlyPayment);

var Tint = 0;
for(i=1;i<payments;i++)
{
interestPayment = principal * monthlyInterest;
principalPayment = monthlyPayment - interestPayment;
principal -= principalPayment;
Tint = Tint + interestPayment;
}

document.form.Tint.value = RND2(Tint);
}

function compute(form)
{
if((form.principal.value.length != 0) &&
(form.apr.value.length != 0) &&
(form.years.value != &quot;0&quot;) && (form.month.value != &quot;0&quot;))
{
principal = eval(form.principal.value);
apr = eval(form.apr.value) / 100.0;
years = (form.years.value);
month = eval(form.month.value);

if(years == 0.0)
{
alert(
&quot;You have no monthly payment, since the number of years is zero.&quot;);
}
else
{
Amortize(principal, years, apr, month);
}
}
else
{
alert(&quot;You must fill in all the fields.&quot;);
}

}

function compute2(form)
{
if((form.principal.value.length != 0) &&
(form.apr.value.length != 0) &&
(form.years.value != &quot;0&quot;) && (form.month.value != &quot;0&quot;))
{
principal = eval(form.principal.value);
apr = eval(form.apr.value) / 100.0;
years = (form.years.value);
month = eval(form.month.value);

if(years == 0.0)
{
alert(
&quot;You have no monthly payment, since the number of years is zero.&quot;);
}
else
{
calculate(principal, years, apr, month);
}
}
else
{
alert(&quot;You must fill in all the fields.&quot;);
}

}
//->

</SCRIPT>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;></HEAD>

<style type=&quot;text/css&quot;>
input, td {
font-family : Verdana, Arial, Helvetica;
font-size : 9pt;
font-style : normal
}
</style>

<BODY bgcolor=&quot;333366&quot;>
<CENTER>
</CENTER>

<CENTER>
<FORM name=form>
<CENTER>
<table width=&quot;500&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; align=center>
<tr>
<td valign=&quot;top&quot;><div align=&quot;center&quot;><img src=&quot;images/mort_calc_txt.gif&quot;></div></td>
</tr>
<tr>
<td>
<TABLE BORDER=0 align=center>
<TR>
<TD colspan=2 align=center><b><font color=&quot;#FFFFFF&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Please
fill in the fields.</font></b></TD>
</TR>
<TR>
<TD align=right><font color=&quot;#FFFFFF&quot; size=&quot;2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Loan
Amount ($)</font></TD>
<TD><INPUT TYPE=TEXT NAME=principal></TD>
</TR>
<TR>
<TD> </TD>
<TD valign=&quot;top&quot;><font color=&quot;#FFFFFF&quot; size=&quot;1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Please do not include commas.
<TR>
<TD align=right><font color=&quot;#FFFFFF&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>APR(%) </font></TD>
<TD><INPUT TYPE=TEXT NAME=apr></TD>
</TR>
<TR>
<TD align=right><font color=&quot;#FFFFFF&quot; size=&quot;2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Length
of loan: </font></TD>
<TD><SELECT NAME=years>
<OPTION value=&quot;0&quot;> -SELECT- </OPTION>
<OPTION value=&quot;5&quot;>5</OPTION>
<OPTION value=&quot;10&quot;>10</OPTION>
<OPTION value=&quot;15&quot;>15</OPTION>
<OPTION value=&quot;20&quot;>20</OPTION>
<OPTION value=&quot;25&quot;>25</OPTION>
<OPTION value=&quot;30&quot;>30</OPTION>
</SELECT> </TD>
</TR>
<TR>
<TD align=right><font color=&quot;#FFFFFF&quot; size=&quot;2&quot;>Starting month: </font></TD>
<TD><SELECT NAME=month>
<OPTION value=0>-SELECT-</OPTION>
<OPTION value=1>January</OPTION>
<OPTION value=2>February</OPTION>
<OPTION value=3>March</OPTION>
<OPTION value=4>April</OPTION>
<OPTION value=5>May</OPTION>
<OPTION value=6>June</OPTION>
<OPTION value=7>July</OPTION>
<OPTION value=8>August</OPTION>
<OPTION value=9>September</OPTION>
<OPTION value=10>October</OPTION>
<OPTION value=11>November</OPTION>
<OPTION value=12>December</OPTION>
</SELECT> </TD>
</TR>
<TR>
<TD align=right><INPUT name=&quot;BUTTON&quot; TYPE=BUTTON onClick=compute(this.form) VALUE=&quot;Amortize&quot;>
 </TD>
<TD><INPUT name=&quot;BUTTON&quot; TYPE=BUTTON onClick=compute2(this.form) VALUE=&quot;Calculate&quot;></TD>
</TR>
<TR>
<TD align=right><font color=&quot;#FFFFFF&quot;>Payment Amount: $</font></TD>
<TD><INPUT type=text name=Total></TD>
</TR>
<TR>
<TD align=right><font color=&quot;#FFFFFF&quot;>Total Interest: $</font></TD>
<TD><INPUT type=text name=Tint></TD>
</TR>
</TABLE></td>
</tr>
</table>
</CENTER>
</FORM>
</CENTER>

</BODY>
</HTML>


 
The only time I've had scripts work in IE but not NS is when I've hung on a document.write(). For some reason NS hates executing tons of doc.writes in succession. Try concating all your strings into one large buffer and writing it all at once.

Other than that, I'm not sure what else to tell you.

- &quot;Delightfully confusing...&quot; raves The New York Times

-Kas
 
jimny,

When you're all done doing your document.write commands, you must execute a document.close command.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Thank you gents,
used both suggestions and have it up and running in NS6, but have issues in 4.7 What can you do? Thank you both!!!
 
I can encourage you to upgrade your browser. [lol]

At exactly which line does it deviate from &quot;works perfectly&quot;?

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top