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%"> </td>
<td width="27%" align="center"><b>Amount to Finance</b></td>
<td width="1%"> </td>
<td width="19%" align="center"><b>Years to Finance</b></td>
</tr>
<tr>
<td width="4%"> </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%"> </td>
<td width="19%" align="center">up to 6 years</td>
</tr>
<tr>
<td width="4%"> </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%"> </td>
<td width="19%" align="center">up to 10 years</td>
</tr>
<tr>
<td width="4%"> </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%"> </td>
<td width="19%" align="center">up to 12 years</td>
</tr>
<tr>
<td width="4%"> </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%"> </td>
<td width="19%" align="center">up to 15 years</td>
</tr>
<tr>
<td width="4%"> </td>
<td width="27%" align="center">over $<span lang="en-us"
xml:lang="en-us">5</span>0,000</td>
<td width="1%"> </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
"Calculate" 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>
===================