Can I Access an ASP variable in Javascript

M

M.Siler

In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the JavaScript
such as in the following code it doens't like it. How can I access that
variable in JavaScript?

if (box.options.value== <%term%>)
 
K

Kevin Spencer

if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
M

M.Siler

Should this work? alert(<%=term%>);



Here's the page I'm working on
http://usawaterskifinance.com/ski-boat-loan-calculator.asp

Here's the section of code:

for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

// if (box.options.value== <%=term%>)
if (box.options.value==96)
{
box.options.selected=true;
}
}

If you use the following values:
Pruchase Price: 30000
Interest Rate: 6%
Loan Term: 6 years

You'll see when you click the "Calculate" button that it does the math and
displays the results that the bottom of the page. You'll note that the Loan
Term goes to "8 Years" and that's becuase I ahve 96 hard coded. Just above
the P in Purchase Price you see 72 which is the number of months in 6 Years
and what is stored in the variable term. When I uncomment the line with the
<%=term%> it stops working. Therefore the value of the <%=term%> is not
being set.


Kevin Spencer said:
if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

M.Siler said:
In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the JavaScript
such as in the following code it doens't like it. How can I access that
variable in JavaScript?

if (box.options.value== <%term%>)

 
R

Ronx

When I uncomment the line with the <%=term%> it stops working

Did you also comment out the line
if (box.options.value==96)
?
If not, the JavaScript is looking for a missing statement
corresponding to the second "if"
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

M.Siler said:
Should this work? alert(<%=term%>);



Here's the page I'm working on
http://usawaterskifinance.com/ski-boat-loan-calculator.asp

Here's the section of code:

for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

// if (box.options.value== <%=term%>)
if (box.options.value==96)
{
box.options.selected=true;
}
}

If you use the following values:
Pruchase Price: 30000
Interest Rate: 6%
Loan Term: 6 years

You'll see when you click the "Calculate" button that it does the
math and displays the results that the bottom of the page. You'll
note that the Loan Term goes to "8 Years" and that's becuase I ahve
96 hard coded. Just above the P in Purchase Price you see 72 which
is the number of months in 6 Years and what is stored in the
variable term. When I uncomment the line with the <%=term%> it stops
working. Therefore the value of the <%=term%> is not being set.


Kevin Spencer said:
if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

M.Siler said:
In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the
JavaScript such as in the following code it doens't like it. How
can I access that variable in JavaScript?

if (box.options.value== <%term%>)


 
M

M.Siler

Yep, commented out the 96 line.

Should alert(<%=term%>); work?

Ronx said:
When I uncomment the line with the <%=term%> it stops working

Did you also comment out the line
if (box.options.value==96)
?
If not, the JavaScript is looking for a missing statement corresponding to
the second "if"
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

M.Siler said:
Should this work? alert(<%=term%>);



Here's the page I'm working on
http://usawaterskifinance.com/ski-boat-loan-calculator.asp

Here's the section of code:

for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

// if (box.options.value== <%=term%>)
if (box.options.value==96)
{
box.options.selected=true;
}
}

If you use the following values:
Pruchase Price: 30000
Interest Rate: 6%
Loan Term: 6 years

You'll see when you click the "Calculate" button that it does the math
and displays the results that the bottom of the page. You'll note that
the Loan Term goes to "8 Years" and that's becuase I ahve 96 hard coded.
Just above the P in Purchase Price you see 72 which is the number of
months in 6 Years and what is stored in the variable term. When I
uncomment the line with the <%=term%> it stops working. Therefore the
value of the <%=term%> is not being set.


Kevin Spencer said:
if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the
JavaScript such as in the following code it doens't like it. How can I
access that variable in JavaScript?

if (box.options.value== <%term%>)


 
M

M.Siler

Between the two lines in the full code to the page.
=======================================

<head>
<title>Loan Calculator</title>
<script language="javascript">
<!--

var lists = new Array();

// $0 to $9,999 up to 6 years
lists['a'] = new Array();
lists['a'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years'
);
lists['a'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72'
);

// $10,000 to $14,999 up to 10 years
lists['b'] = new Array();
lists['b'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years'
);
lists['b'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120'
);

// $15,000 to $24,999 up to 12 years
lists['c'] = new Array();
lists['c'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years'
);
lists['c'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144'
);

// $25,000 to 49,999 up to 15 years
lists['d'] = new Array();
lists['d'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years',
'13 Years',
'14 Years',
'15 Years'
);
lists['d'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144',
'156',
'168',
'180'
);

// over $50,000 up to 20 years
lists['e'] = new Array();
lists['e'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years',
'13 Years',
'14 Years',
'15 Years',
'16 Years',
'17 Years',
'18 Years',
'19 Years',
'20 Years'
);
lists['e'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144',
'156',
'168',
'180',
'192',
'204',
'216',
'228',
'240'
);


function emptyList( box )
{
while ( box.options.length ) box.options[0] = null;
}

function changeList()
{
amt2finance = document.calculator.PurchasePrice.value -
document.calculator.DownPayment.value;

if (amt2finance < 0) amt2finance=0;

if (amt2finance >= 0 && amt2finance < 10000)
{
list = lists['a'];
}
else if (amt2finance >= 10000 && amt2finance < 15000)
{
list = lists['b'];
}
else if (amt2finance >= 15000 && amt2finance < 25000)
{
list = lists['c'];
}
else if (amt2finance >= 25000 && amt2finance < 50000)
{
list = lists['d'];
}
else
{
list = lists['e'];
}

emptyList( document.calculator.term );
fillList( document.calculator.term, list );
}

function fillList( box, arr )
{
for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

}
box.selectedIndex=0;
}
//-->
</script>
</head>

<body onload="changeList();">
<%
Dim PurchasePrice, DownPayment, InterestRate, term, FinanceAmount

PurchasePrice=Request.Form("PurchasePrice")
IF (PurchasePrice = "") THEN
PurchasePrice = 0.00
END IF

DownPayment=Request.Form("DownPayment")
IF (DownPayment = "") THEN
DownPayment = 0.00
END IF

FinanceAmount = PurchasePrice - DownPayment
IF FinanceAmount < 0 then FinanceAmount = 0.00

InterestRate=Request.Form("InterestRate")
IF (InterestRate = "") THEN
InterestRate = 0.00
END IF

SalesTax=Request.Form("SalesTax")
IF (SalesTax = "") THEN
SalesTax = 0.00
END IF

RegFee=Request.Form("RegFee")
IF (RegFee = "") THEN
RegFee = 0.00
END IF

term=Request.Form("term")
IF (term = "") THEN
term = 12
END IF
%>

<div align="center">
<table width="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="49%" rowspan="6">
<form name="calculator" action="loan-calculator.asp" method="post" form
style="display:inline">
<table border="0" cellspacing="4" cellpadding="0">
<tr>
<td align="right">Purchase Price: $</td>
<td><input type="text" name="PurchasePrice" value="<%Response.Write
PurchasePrice%>" size="10" onchange="changeList();"/></td>
</tr>
<tr>
<td align="right">Down Payment: $</td>
<td><input type="text" name="DownPayment" value="<%Response.Write
DownPayment%>" size="10" onchange="changeList();"/></td>
</tr>
<tr>
<td align="right">Interest Rate: %</td>
<td><input type="text" name="InterestRate" value="<%Response.Write
InterestRate%>" size="10" /></td>
</tr>
<tr>
<td align="right">Loan Term:</td>
<td><select name="term" size="1" >
<option value="12">1 Year
</select>
</td>
</tr>
<tr>
<td align="right">Sales Tax: %</td>
<td nowrap="nowrap"><input type="text" name="SalesTax"
value="<%Response.Write SalesTax%>" size="10" />
<small class="small">(optional)</small> </td>
</tr>
<tr>
<td align="right">Registration Fee: $</td>
<td><input type="text" name="RegFee" value="<%Response.Write
RegFee%>" size="10" />
<small class="small">(optional)</small> </td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="Submit"
value="Calculate" class="button" /> </td>
</tr>
</table>
</form>
</td>
<td width="4%">&nbsp;</td>
<td width="27%" align="center"><b>Amount to Finance</b></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center"><b>Years to Finance</b></td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$0 to $<span lang="en-us"
xml:lang="en-us">9</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 6 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$10,000 to $1<span lang="en-us"
xml:lang="en-us">4</span>,<span lang="en-us" xml:lang="en-us">999</span>
</td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 10 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$15,000 to $2<span lang="en-us"
xml:lang="en-us">4</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 12 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$25,000 to $<span lang="en-us"
xml:lang="en-us">49</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 15 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">over $<span lang="en-us"
xml:lang="en-us">5</span>0,000</td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 20 years
</td>
</tr>
<tr>
<td colspan="5"><br><a name="results" id="results"></a><img
src="images/h_results.png" alt="Results" width="118" height="35" /></td>
</tr>
<tr>
<td colspan="5">
<%
SalesTaxAmt = PurchasePrice * (SalesTax / 100)
AmountFinanced = (PurchasePrice - DownPayment) + SalesTaxAmt + RegFee

IF (AmountFinanced < .01) THEN
Response.Write("What would you like your monthly payment to be?
Please enter the calculation information above and click the
&quot;Calculate&quot; button.")
END IF

IF (InterestRate > 0 and AmountFinanced > 0 and term > 0) THEN

MonthlyPayment=((AmountFinanced*(InterestRate/100)/12)/(1-(1+(InterestRate/100)/12)^-term))
Response.Write("• Financing "&FormatCurrency(AmountFinanced)&"
for a "&term&" month ("&term/12&" year) term will result in an approximate
payment of <b>" & FormatCurrency(MonthlyPayment) & "</b> a month.<BR>")

END IF
%>
</td>
</tr>
</table>
</div>
</body>
</html>

=======================================
M.Siler said:
Yep, commented out the 96 line.

Should alert(<%=term%>); work?

Ronx said:
When I uncomment the line with the <%=term%> it stops working

Did you also comment out the line
if (box.options.value==96)
?
If not, the JavaScript is looking for a missing statement corresponding
to the second "if"
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

M.Siler said:
Should this work? alert(<%=term%>);



Here's the page I'm working on
http://usawaterskifinance.com/ski-boat-loan-calculator.asp

Here's the section of code:

for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

// if (box.options.value== <%=term%>)
if (box.options.value==96)
{
box.options.selected=true;
}
}

If you use the following values:
Pruchase Price: 30000
Interest Rate: 6%
Loan Term: 6 years

You'll see when you click the "Calculate" button that it does the math
and displays the results that the bottom of the page. You'll note that
the Loan Term goes to "8 Years" and that's becuase I ahve 96 hard coded.
Just above the P in Purchase Price you see 72 which is the number of
months in 6 Years and what is stored in the variable term. When I
uncomment the line with the <%=term%> it stops working. Therefore the
value of the <%=term%> is not being set.


if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the
JavaScript such as in the following code it doens't like it. How can I
access that variable in JavaScript?

if (box.options.value== <%term%>)


 
K

Kevin Spencer

My apologies. You need to add the quotation marks:

alert("<%=term%>");

The variable will be added to the page as text. Since JavaScript requires
the quotation marks around the text passed to it (to indicate that it is
text), you need to add them around the script tag.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

M.Siler said:
Yep, commented out the 96 line.

Should alert(<%=term%>); work?

Ronx said:
When I uncomment the line with the <%=term%> it stops working

Did you also comment out the line
if (box.options.value==96)
?
If not, the JavaScript is looking for a missing statement corresponding
to the second "if"
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

M.Siler said:
Should this work? alert(<%=term%>);



Here's the page I'm working on
http://usawaterskifinance.com/ski-boat-loan-calculator.asp

Here's the section of code:

for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

// if (box.options.value== <%=term%>)
if (box.options.value==96)
{
box.options.selected=true;
}
}

If you use the following values:
Pruchase Price: 30000
Interest Rate: 6%
Loan Term: 6 years

You'll see when you click the "Calculate" button that it does the math
and displays the results that the bottom of the page. You'll note that
the Loan Term goes to "8 Years" and that's becuase I ahve 96 hard coded.
Just above the P in Purchase Price you see 72 which is the number of
months in 6 Years and what is stored in the variable term. When I
uncomment the line with the <%=term%> it stops working. Therefore the
value of the <%=term%> is not being set.


if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the
JavaScript such as in the following code it doens't like it. How can I
access that variable in JavaScript?

if (box.options.value== <%term%>)


 
R

Ronx

No,
but

<script type="text/javascript">
alert("<%=term%>")
</script>

will.
Note the quotes around the ASP.
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

M.Siler said:
Yep, commented out the 96 line.

Should alert(<%=term%>); work?

Ronx said:
When I uncomment the line with the <%=term%> it stops working

Did you also comment out the line
if (box.options.value==96)
?
If not, the JavaScript is looking for a missing statement
corresponding to the second "if"
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

M.Siler said:
Should this work? alert(<%=term%>);



Here's the page I'm working on
http://usawaterskifinance.com/ski-boat-loan-calculator.asp

Here's the section of code:

for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

// if (box.options.value== <%=term%>)
if (box.options.value==96)
{
box.options.selected=true;
}
}

If you use the following values:
Pruchase Price: 30000
Interest Rate: 6%
Loan Term: 6 years

You'll see when you click the "Calculate" button that it does the
math and displays the results that the bottom of the page. You'll
note that the Loan Term goes to "8 Years" and that's becuase I
ahve 96 hard coded. Just above the P in Purchase Price you see 72
which is the number of months in 6 Years and what is stored in the
variable term. When I uncomment the line with the <%=term%> it
stops working. Therefore the value of the <%=term%> is not being
set.


message if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the
JavaScript such as in the following code it doens't like it. How
can I access that variable in JavaScript?

if (box.options.value== <%term%>)


 
M

M.Siler

Still doesn't work. The alert window is blank. I'll fall back and punt (I'll
print a table with all the years listed and not let the user pick the year).

Kevin Spencer said:
My apologies. You need to add the quotation marks:

alert("<%=term%>");

The variable will be added to the page as text. Since JavaScript requires
the quotation marks around the text passed to it (to indicate that it is
text), you need to add them around the script tag.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

M.Siler said:
Yep, commented out the 96 line.

Should alert(<%=term%>); work?

Ronx said:
When I uncomment the line with the <%=term%> it stops working

Did you also comment out the line
if (box.options.value==96)
?
If not, the JavaScript is looking for a missing statement corresponding
to the second "if"
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

Should this work? alert(<%=term%>);



Here's the page I'm working on
http://usawaterskifinance.com/ski-boat-loan-calculator.asp

Here's the section of code:

for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

// if (box.options.value== <%=term%>)
if (box.options.value==96)
{
box.options.selected=true;
}
}

If you use the following values:
Pruchase Price: 30000
Interest Rate: 6%
Loan Term: 6 years

You'll see when you click the "Calculate" button that it does the math
and displays the results that the bottom of the page. You'll note that
the Loan Term goes to "8 Years" and that's becuase I ahve 96 hard
coded. Just above the P in Purchase Price you see 72 which is the
number of months in 6 Years and what is stored in the variable term.
When I uncomment the line with the <%=term%> it stops working.
Therefore the value of the <%=term%> is not being set.


if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the
JavaScript such as in the following code it doens't like it. How can
I access that variable in JavaScript?

if (box.options.value== <%term%>)


 
K

Kevin Spencer

Okay, your syntax:

<%=term%>

means "Write the value of the variable "term" to the page here.

Does the variable "term" have a value?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

M.Siler said:
Still doesn't work. The alert window is blank. I'll fall back and punt
(I'll print a table with all the years listed and not let the user pick
the year).

Kevin Spencer said:
My apologies. You need to add the quotation marks:

alert("<%=term%>");

The variable will be added to the page as text. Since JavaScript requires
the quotation marks around the text passed to it (to indicate that it is
text), you need to add them around the script tag.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

M.Siler said:
Yep, commented out the 96 line.

Should alert(<%=term%>); work?

When I uncomment the line with the <%=term%> it stops working

Did you also comment out the line
if (box.options.value==96)
?
If not, the JavaScript is looking for a missing statement corresponding
to the second "if"
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

Should this work? alert(<%=term%>);



Here's the page I'm working on
http://usawaterskifinance.com/ski-boat-loan-calculator.asp

Here's the section of code:

for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

// if (box.options.value== <%=term%>)
if (box.options.value==96)
{
box.options.selected=true;
}
}

If you use the following values:
Pruchase Price: 30000
Interest Rate: 6%
Loan Term: 6 years

You'll see when you click the "Calculate" button that it does the math
and displays the results that the bottom of the page. You'll note that
the Loan Term goes to "8 Years" and that's becuase I ahve 96 hard
coded. Just above the P in Purchase Price you see 72 which is the
number of months in 6 Years and what is stored in the variable term.
When I uncomment the line with the <%=term%> it stops working.
Therefore the value of the <%=term%> is not being set.


if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the
JavaScript such as in the following code it doens't like it. How can
I access that variable in JavaScript?

if (box.options.value== <%term%>)


 
R

Ronx

See http://www.rxs-enterprises.org/tests/pages/terms.asp
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

M.Siler said:
Still doesn't work. The alert window is blank. I'll fall back and
punt (I'll print a table with all the years listed and not let the
user pick the year).

Kevin Spencer said:
My apologies. You need to add the quotation marks:

alert("<%=term%>");

The variable will be added to the page as text. Since JavaScript
requires the quotation marks around the text passed to it (to
indicate that it is text), you need to add them around the script
tag.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

M.Siler said:
Yep, commented out the 96 line.

Should alert(<%=term%>); work?

When I uncomment the line with the <%=term%> it stops working

Did you also comment out the line
if (box.options.value==96)
?
If not, the JavaScript is looking for a missing statement
corresponding to the second "if"
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

Should this work? alert(<%=term%>);



Here's the page I'm working on
http://usawaterskifinance.com/ski-boat-loan-calculator.asp

Here's the section of code:

for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

// if (box.options.value== <%=term%>)
if (box.options.value==96)
{
box.options.selected=true;
}
}

If you use the following values:
Pruchase Price: 30000
Interest Rate: 6%
Loan Term: 6 years

You'll see when you click the "Calculate" button that it does
the math and displays the results that the bottom of the page.
You'll note that the Loan Term goes to "8 Years" and that's
becuase I ahve 96 hard coded. Just above the P in Purchase Price
you see 72 which is the number of months in 6 Years and what is
stored in the variable term. When I uncomment the line with the
<%=term%> it stops working. Therefore the value of the <%=term%>
is not being set.


message if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the
JavaScript such as in the following code it doens't like it.
How can I access that variable in JavaScript?

if (box.options.value== <%term%>)


 
M

M.Siler

yep... if you go to the link
http://usawaterskifinance.com/loan-calculator.asp you'll see the value for
term printed on the page in the result section when it lists the number of
months... that's the term. You'll see next to it the number of years, that's
what I'm trying to set the drop down back to. It works fine and the drop
down box is set back to what I hard when I hard code the value in the line.

if (box.options.value==96)

but when I put in

if (box.options.value=="<%=term%>")

It doesn't work, even though there is a value for term. I don't think the
syntax is correct in referencing term in the Javascript code becuase when I
put in

alert("<%=term%>");

I get an empty alert window where there *IS* a value for term becuase it
prints in the results section of the page... see the code at the very
bottom.

Below is the ASP page for the link
=================================

<head>
<title>Loan Calculator</title>
<script language="javascript">
<!--

var lists = new Array();

// $0 to $9,999 up to 6 years
lists['a'] = new Array();
lists['a'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years'
);
lists['a'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72'
);

// $10,000 to $14,999 up to 10 years
lists['b'] = new Array();
lists['b'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years'
);
lists['b'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120'
);

// $15,000 to $24,999 up to 12 years
lists['c'] = new Array();
lists['c'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years'
);
lists['c'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144'
);

// $25,000 to 49,999 up to 15 years
lists['d'] = new Array();
lists['d'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years',
'13 Years',
'14 Years',
'15 Years'
);
lists['d'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144',
'156',
'168',
'180'
);

// over $50,000 up to 20 years
lists['e'] = new Array();
lists['e'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years',
'13 Years',
'14 Years',
'15 Years',
'16 Years',
'17 Years',
'18 Years',
'19 Years',
'20 Years'
);
lists['e'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144',
'156',
'168',
'180',
'192',
'204',
'216',
'228',
'240'
);


function emptyList( box )
{
while ( box.options.length ) box.options[0] = null;
}

function changeList()
{
amt2finance = document.calculator.PurchasePrice.value -
document.calculator.DownPayment.value;

if (amt2finance < 0) amt2finance=0;

if (amt2finance >= 0 && amt2finance < 10000)
{
list = lists['a'];
}
else if (amt2finance >= 10000 && amt2finance < 15000)
{
list = lists['b'];
}
else if (amt2finance >= 15000 && amt2finance < 25000)
{
list = lists['c'];
}
else if (amt2finance >= 25000 && amt2finance < 50000)
{
list = lists['d'];
}
else
{
list = lists['e'];
}

emptyList( document.calculator.term );
fillList( document.calculator.term, list );
}

function fillList( box, arr )
{
for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

if (box.options.value=="<%=term%>")
// if (box.options.value==96)
{
box.options.selected=true;
}
}
// box.selectedIndex=0;
}

//-->
</script>
</head>

<body onload="changeList();">
<%
Dim PurchasePrice, DownPayment, InterestRate, term, FinanceAmount

PurchasePrice=Request.Form("PurchasePrice")
IF (PurchasePrice = "") THEN
PurchasePrice = 0.00
END IF

DownPayment=Request.Form("DownPayment")
IF (DownPayment = "") THEN
DownPayment = 0.00
END IF

FinanceAmount = PurchasePrice - DownPayment
IF FinanceAmount < 0 then FinanceAmount = 0.00

InterestRate=Request.Form("InterestRate")
IF (InterestRate = "") THEN
InterestRate = 0.00
END IF

SalesTax=Request.Form("SalesTax")
IF (SalesTax = "") THEN
SalesTax = 0.00
END IF

RegFee=Request.Form("RegFee")
IF (RegFee = "") THEN
RegFee = 0.00
END IF

term=Request.Form("term")
IF (term = "") THEN
term = 12
END IF
%>

<div align="center">
<table width="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="49%" rowspan="6">
<form name="calculator" action="loan-calculator.asp" method="post" form
style="display:inline">
<table border="0" cellspacing="4" cellpadding="0">
<tr>
<td align="right">Purchase Price: $</td>
<td><input type="text" name="PurchasePrice" value="<%Response.Write
PurchasePrice%>" size="10" onchange="changeList();"/></td>
</tr>
<tr>
<td align="right">Down Payment: $</td>
<td><input type="text" name="DownPayment" value="<%Response.Write
DownPayment%>" size="10" onchange="changeList();"/></td>
</tr>
<tr>
<td align="right">Interest Rate: %</td>
<td><input type="text" name="InterestRate" value="<%Response.Write
InterestRate%>" size="10" /></td>
</tr>
<tr>
<td align="right">Loan Term:</td>
<td><select name="term" size="1" >
<option value="12">1 Year
</select>
</td>
</tr>
<tr>
<td align="right">Sales Tax: %</td>
<td nowrap="nowrap"><input type="text" name="SalesTax"
value="<%Response.Write SalesTax%>" size="10" />
<small class="small">(optional)</small> </td>
</tr>
<tr>
<td align="right">Registration Fee: $</td>
<td><input type="text" name="RegFee" value="<%Response.Write
RegFee%>" size="10" />
<small class="small">(optional)</small> </td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="Submit"
value="Calculate" class="button" /> </td>
</tr>
</table>
</form>
</td>
<td width="4%">&nbsp;</td>
<td width="27%" align="center"><b>Amount to Finance</b></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center"><b>Years to Finance</b></td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$0 to $<span lang="en-us"
xml:lang="en-us">9</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 6 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$10,000 to $1<span lang="en-us"
xml:lang="en-us">4</span>,<span lang="en-us" xml:lang="en-us">999</span>
</td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 10 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$15,000 to $2<span lang="en-us"
xml:lang="en-us">4</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 12 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$25,000 to $<span lang="en-us"
xml:lang="en-us">49</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 15 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">over $<span lang="en-us"
xml:lang="en-us">5</span>0,000</td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 20 years
</td>
</tr>
<tr>
<td colspan="5"><br><a name="results" id="results"></a><img
src="images/h_results.png" alt="Results" width="118" height="35" /></td>
</tr>
<tr>
<td colspan="5">
<%
SalesTaxAmt = PurchasePrice * (SalesTax / 100)
AmountFinanced = (PurchasePrice - DownPayment) + SalesTaxAmt + RegFee

IF (AmountFinanced < .01) THEN
Response.Write("What would you like your monthly payment to be?
Please enter the calculation information above and click the
&quot;Calculate&quot; button.")
END IF

IF (InterestRate > 0 and AmountFinanced > 0 and term > 0) THEN

MonthlyPayment=((AmountFinanced*(InterestRate/100)/12)/(1-(1+(InterestRate/100)/12)^-term))
Response.Write("• Financing "&FormatCurrency(AmountFinanced)&"
for a "&term&" month ("&term/12&" year) term will result in an approximate
payment of <b>" & FormatCurrency(MonthlyPayment) & "</b> a month.<BR>")

END IF
%>
</td>
</tr>
</table>
</div>
</body>
</html>

=================================
 
M

M.Siler

Ok... now I'll see how my code is different. Thank you for you help. I'll
post back here what I find.

Ronx said:
See http://www.rxs-enterprises.org/tests/pages/terms.asp
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

M.Siler said:
Still doesn't work. The alert window is blank. I'll fall back and punt
(I'll print a table with all the years listed and not let the user pick
the year).

Kevin Spencer said:
My apologies. You need to add the quotation marks:

alert("<%=term%>");

The variable will be added to the page as text. Since JavaScript
requires the quotation marks around the text passed to it (to indicate
that it is text), you need to add them around the script tag.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

Yep, commented out the 96 line.

Should alert(<%=term%>); work?

When I uncomment the line with the <%=term%> it stops working

Did you also comment out the line
if (box.options.value==96)
?
If not, the JavaScript is looking for a missing statement
corresponding to the second "if"
--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.
FrontPage Support: http://www.frontpagemvps.com/

Should this work? alert(<%=term%>);



Here's the page I'm working on
http://usawaterskifinance.com/ski-boat-loan-calculator.asp

Here's the section of code:

for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

// if (box.options.value== <%=term%>)
if (box.options.value==96)
{
box.options.selected=true;
}
}

If you use the following values:
Pruchase Price: 30000
Interest Rate: 6%
Loan Term: 6 years

You'll see when you click the "Calculate" button that it does the
math and displays the results that the bottom of the page. You'll
note that the Loan Term goes to "8 Years" and that's becuase I ahve
96 hard coded. Just above the P in Purchase Price you see 72 which is
the number of months in 6 Years and what is stored in the variable
term. When I uncomment the line with the <%=term%> it stops working.
Therefore the value of the <%=term%> is not being set.


if (box.options.value== <%=term%>)

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

In ASP I can get the value: Response.Write(term)

but in JavaScript if I want to embed the value of term in the
JavaScript such as in the following code it doens't like it. How
can I access that variable in JavaScript?

if (box.options.value== <%term%>)


 
M

M.Siler

That little example was just what I needed... The problem was that the
function for setting the drop down was above the ASP code that populated
"term". Man do I feel stupid.

Thanks for your help.

For anyone that is following this thread and wants the working code here it
is:

===================


<head>
<title>Loan Calculator</title>
<script language="javascript">
<!--

var lists = new Array();

// $0 to $9,999 up to 6 years
lists['a'] = new Array();
lists['a'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years'
);
lists['a'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72'
);

// $10,000 to $14,999 up to 10 years
lists['b'] = new Array();
lists['b'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years'
);
lists['b'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120'
);

// $15,000 to $24,999 up to 12 years
lists['c'] = new Array();
lists['c'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years'
);
lists['c'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144'
);

// $25,000 to 49,999 up to 15 years
lists['d'] = new Array();
lists['d'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years',
'13 Years',
'14 Years',
'15 Years'
);
lists['d'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144',
'156',
'168',
'180'
);

// over $50,000 up to 20 years
lists['e'] = new Array();
lists['e'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years',
'13 Years',
'14 Years',
'15 Years',
'16 Years',
'17 Years',
'18 Years',
'19 Years',
'20 Years'
);
lists['e'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144',
'156',
'168',
'180',
'192',
'204',
'216',
'228',
'240'
);

//-->
</script>
</head>

<body onload="changeList();">
<%
Dim PurchasePrice, DownPayment, InterestRate, term, FinanceAmount

PurchasePrice=Request.Form("PurchasePrice")
IF (PurchasePrice = "") THEN
PurchasePrice = 0.00
END IF

DownPayment=Request.Form("DownPayment")
IF (DownPayment = "") THEN
DownPayment = 0.00
END IF

FinanceAmount = PurchasePrice - DownPayment
IF FinanceAmount < 0 then FinanceAmount = 0.00

InterestRate=Request.Form("InterestRate")
IF (InterestRate = "") THEN
InterestRate = 0.00
END IF

SalesTax=Request.Form("SalesTax")
IF (SalesTax = "") THEN
SalesTax = 0.00
END IF

RegFee=Request.Form("RegFee")
IF (RegFee = "") THEN
RegFee = 0.00
END IF

term=Request.Form("term")
IF (term = "") THEN
term = 12
END IF
%>

<script language="javascript">
<!--

function emptyList( box )
{
while ( box.options.length ) box.options[0] = null;
}

function changeList()
{
amt2finance = document.calculator.PurchasePrice.value -
document.calculator.DownPayment.value;

if (amt2finance < 0) amt2finance=0;

if (amt2finance >= 0 && amt2finance < 10000)
{
list = lists['a'];
}
else if (amt2finance >= 10000 && amt2finance < 15000)
{
list = lists['b'];
}
else if (amt2finance >= 15000 && amt2finance < 25000)
{
list = lists['c'];
}
else if (amt2finance >= 25000 && amt2finance < 50000)
{
list = lists['d'];
}
else
{
list = lists['e'];
}

emptyList( document.calculator.term );
fillList( document.calculator.term, list );
}

function fillList( box, arr )
{
for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

if (box.options.value=="<%=term%>")
// if (box.options.value==96)
{
box.options.selected=true;
}
}
// box.selectedIndex=0;
}

//-->
</script>


<div align="center">
<table width="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="49%" rowspan="6">
<form name="calculator" action="loan-calculator.asp" method="post" form
style="display:inline">
<table border="0" cellspacing="4" cellpadding="0">
<tr>
<td align="right">Purchase Price: $</td>
<td><input type="text" name="PurchasePrice" value="<%Response.Write
PurchasePrice%>" size="10" onchange="changeList();"/></td>
</tr>
<tr>
<td align="right">Down Payment: $</td>
<td><input type="text" name="DownPayment" value="<%Response.Write
DownPayment%>" size="10" onchange="changeList();"/></td>
</tr>
<tr>
<td align="right">Interest Rate: %</td>
<td><input type="text" name="InterestRate" value="<%Response.Write
InterestRate%>" size="10" /></td>
</tr>
<tr>
<td align="right">Loan Term:</td>
<td><select name="term" size="1" >
<option value="12">1 Year
</select>
</td>
</tr>
<tr>
<td align="right">Sales Tax: %</td>
<td nowrap="nowrap"><input type="text" name="SalesTax"
value="<%Response.Write SalesTax%>" size="10" />
<small class="small">(optional)</small> </td>
</tr>
<tr>
<td align="right">Registration Fee: $</td>
<td><input type="text" name="RegFee" value="<%Response.Write
RegFee%>" size="10" />
<small class="small">(optional)</small> </td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="Submit"
value="Calculate" class="button" /> </td>
</tr>
</table>
</form>
</td>
<td width="4%">&nbsp;</td>
<td width="27%" align="center"><b>Amount to Finance</b></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center"><b>Years to Finance</b></td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$0 to $<span lang="en-us"
xml:lang="en-us">9</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 6 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$10,000 to $1<span lang="en-us"
xml:lang="en-us">4</span>,<span lang="en-us" xml:lang="en-us">999</span>
</td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 10 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$15,000 to $2<span lang="en-us"
xml:lang="en-us">4</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 12 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$25,000 to $<span lang="en-us"
xml:lang="en-us">49</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 15 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">over $<span lang="en-us"
xml:lang="en-us">5</span>0,000</td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 20 years
</td>
</tr>
<tr>
<td colspan="5"><br><a name="results" id="results"></a><img
src="images/h_results.png" alt="Results" width="118" height="35" /></td>
</tr>
<tr>
<td colspan="5">
<%
SalesTaxAmt = PurchasePrice * (SalesTax / 100)
AmountFinanced = (PurchasePrice - DownPayment) + SalesTaxAmt + RegFee

IF (AmountFinanced < .01) THEN
Response.Write("What would you like your monthly payment to be?
Please enter the calculation information above and click the
&quot;Calculate&quot; button.")
END IF

IF (InterestRate > 0 and AmountFinanced > 0 and term > 0) THEN

MonthlyPayment=((AmountFinanced*(InterestRate/100)/12)/(1-(1+(InterestRate/100)/12)^-term))
Response.Write("• Financing "&FormatCurrency(AmountFinanced)&"
for a "&term&" month ("&term/12&" year) term will result in an approximate
payment of <b>" & FormatCurrency(MonthlyPayment) & "</b> a month.<BR>")

END IF
%>
</td>
</tr>
</table>
</div>
</body>
</html>

===================
 
M

M.Siler

Got it... The problem was that the function for setting the drop down was
above the ASP code that populated "term". Man do I feel stupid.

Thanks for your help.


M.Siler said:
yep... if you go to the link
http://usawaterskifinance.com/loan-calculator.asp you'll see the value
for term printed on the page in the result section when it lists the
number of months... that's the term. You'll see next to it the number of
years, that's what I'm trying to set the drop down back to. It works fine
and the drop down box is set back to what I hard when I hard code the
value in the line.

if (box.options.value==96)

but when I put in

if (box.options.value=="<%=term%>")

It doesn't work, even though there is a value for term. I don't think the
syntax is correct in referencing term in the Javascript code becuase when
I put in

alert("<%=term%>");

I get an empty alert window where there *IS* a value for term becuase it
prints in the results section of the page... see the code at the very
bottom.

Below is the ASP page for the link
=================================

<head>
<title>Loan Calculator</title>
<script language="javascript">
<!--

var lists = new Array();

// $0 to $9,999 up to 6 years
lists['a'] = new Array();
lists['a'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years'
);
lists['a'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72'
);

// $10,000 to $14,999 up to 10 years
lists['b'] = new Array();
lists['b'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years'
);
lists['b'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120'
);

// $15,000 to $24,999 up to 12 years
lists['c'] = new Array();
lists['c'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years'
);
lists['c'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144'
);

// $25,000 to 49,999 up to 15 years
lists['d'] = new Array();
lists['d'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years',
'13 Years',
'14 Years',
'15 Years'
);
lists['d'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144',
'156',
'168',
'180'
);

// over $50,000 up to 20 years
lists['e'] = new Array();
lists['e'][0] = new Array(
'1 Year',
'2 Years',
'3 Years',
'4 Years',
'5 Years',
'6 Years',
'7 Years',
'8 Years',
'9 Years',
'10 Years',
'11 Years',
'12 Years',
'13 Years',
'14 Years',
'15 Years',
'16 Years',
'17 Years',
'18 Years',
'19 Years',
'20 Years'
);
lists['e'][1] = new Array(
'12',
'24',
'36',
'48',
'60',
'72',
'84',
'96',
'108',
'120',
'132',
'144',
'156',
'168',
'180',
'192',
'204',
'216',
'228',
'240'
);


function emptyList( box )
{
while ( box.options.length ) box.options[0] = null;
}

function changeList()
{
amt2finance = document.calculator.PurchasePrice.value -
document.calculator.DownPayment.value;

if (amt2finance < 0) amt2finance=0;

if (amt2finance >= 0 && amt2finance < 10000)
{
list = lists['a'];
}
else if (amt2finance >= 10000 && amt2finance < 15000)
{
list = lists['b'];
}
else if (amt2finance >= 15000 && amt2finance < 25000)
{
list = lists['c'];
}
else if (amt2finance >= 25000 && amt2finance < 50000)
{
list = lists['d'];
}
else
{
list = lists['e'];
}

emptyList( document.calculator.term );
fillList( document.calculator.term, list );
}

function fillList( box, arr )
{
for ( i = 0; i < arr[0].length; i++ )
{
option = new Option( arr[0], arr[1] );
box.options[box.length] = option;

if (box.options.value=="<%=term%>")
// if (box.options.value==96)
{
box.options.selected=true;
}
}
// box.selectedIndex=0;
}

//-->
</script>
</head>

<body onload="changeList();">
<%
Dim PurchasePrice, DownPayment, InterestRate, term, FinanceAmount

PurchasePrice=Request.Form("PurchasePrice")
IF (PurchasePrice = "") THEN
PurchasePrice = 0.00
END IF

DownPayment=Request.Form("DownPayment")
IF (DownPayment = "") THEN
DownPayment = 0.00
END IF

FinanceAmount = PurchasePrice - DownPayment
IF FinanceAmount < 0 then FinanceAmount = 0.00

InterestRate=Request.Form("InterestRate")
IF (InterestRate = "") THEN
InterestRate = 0.00
END IF

SalesTax=Request.Form("SalesTax")
IF (SalesTax = "") THEN
SalesTax = 0.00
END IF

RegFee=Request.Form("RegFee")
IF (RegFee = "") THEN
RegFee = 0.00
END IF

term=Request.Form("term")
IF (term = "") THEN
term = 12
END IF
%>

<div align="center">
<table width="600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="49%" rowspan="6">
<form name="calculator" action="loan-calculator.asp" method="post" form
style="display:inline">
<table border="0" cellspacing="4" cellpadding="0">
<tr>
<td align="right">Purchase Price: $</td>
<td><input type="text" name="PurchasePrice" value="<%Response.Write
PurchasePrice%>" size="10" onchange="changeList();"/></td>
</tr>
<tr>
<td align="right">Down Payment: $</td>
<td><input type="text" name="DownPayment" value="<%Response.Write
DownPayment%>" size="10" onchange="changeList();"/></td>
</tr>
<tr>
<td align="right">Interest Rate: %</td>
<td><input type="text" name="InterestRate" value="<%Response.Write
InterestRate%>" size="10" /></td>
</tr>
<tr>
<td align="right">Loan Term:</td>
<td><select name="term" size="1" >
<option value="12">1 Year
</select>
</td>
</tr>
<tr>
<td align="right">Sales Tax: %</td>
<td nowrap="nowrap"><input type="text" name="SalesTax"
value="<%Response.Write SalesTax%>" size="10" />
<small class="small">(optional)</small> </td>
</tr>
<tr>
<td align="right">Registration Fee: $</td>
<td><input type="text" name="RegFee" value="<%Response.Write
RegFee%>" size="10" />
<small class="small">(optional)</small> </td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="Submit"
value="Calculate" class="button" /> </td>
</tr>
</table>
</form>
</td>
<td width="4%">&nbsp;</td>
<td width="27%" align="center"><b>Amount to Finance</b></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center"><b>Years to Finance</b></td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$0 to $<span lang="en-us"
xml:lang="en-us">9</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 6 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$10,000 to $1<span lang="en-us"
xml:lang="en-us">4</span>,<span lang="en-us" xml:lang="en-us">999</span>
</td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 10 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$15,000 to $2<span lang="en-us"
xml:lang="en-us">4</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 12 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">$25,000 to $<span lang="en-us"
xml:lang="en-us">49</span>,<span lang="en-us"
xml:lang="en-us">999</span></td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 15 years</td>
</tr>
<tr>
<td width="4%">&nbsp;</td>
<td width="27%" align="center">over $<span lang="en-us"
xml:lang="en-us">5</span>0,000</td>
<td width="1%">&nbsp;</td>
<td width="19%" align="center">up to 20 years
</td>
</tr>
<tr>
<td colspan="5"><br><a name="results" id="results"></a><img
src="images/h_results.png" alt="Results" width="118" height="35" /></td>
</tr>
<tr>
<td colspan="5">
<%
SalesTaxAmt = PurchasePrice * (SalesTax / 100)
AmountFinanced = (PurchasePrice - DownPayment) + SalesTaxAmt + RegFee

IF (AmountFinanced < .01) THEN
Response.Write("What would you like your monthly payment to be?
Please enter the calculation information above and click the
&quot;Calculate&quot; button.")
END IF

IF (InterestRate > 0 and AmountFinanced > 0 and term > 0) THEN


MonthlyPayment=((AmountFinanced*(InterestRate/100)/12)/(1-(1+(InterestRate/100)/12)^-term))
Response.Write("• Financing "&FormatCurrency(AmountFinanced)&"
for a "&term&" month ("&term/12&" year) term will result in an approximate
payment of <b>" & FormatCurrency(MonthlyPayment) & "</b> a month.<BR>")

END IF
%>
</td>
</tr>
</table>
</div>
</body>
</html>

=================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top