Dynamically adjust array's upper limit

M

M.Siler

I'm working on a page where a drop down box needs to display different
elements based on a two values entered in two text fields on a form. You can
see an example of it at
http://usawaterskifinance.com/ski-boat-loan-calculator.asp and the ASP code
is in this ZIP file
http://usawaterskifinance.com/ski-boat-loan-calculator.zip

It works, but the problem I'm having is that when it redisplays the page it
loses which field I was going to next. I thought this could be resolved by
change the ASP code to JavaScript. I'm not sure of the exact syntax but my
thought was as follows:

Create a single array that held the values "1 year" through "20 years". Then
when the onchange for Purchase Price and/or Down Payment is triggered it is
sent to a function "setupperlimit" where the upper end of the array is set
via an if statement.

<script type="text/javascript">
<!--
var yeararray=new Array()
yeararray[0]="1 year"
yeararray[1]="2 years"
yeararray[2]="3 years"
yeararray[3]="4 years"
yeararray[4]="5 years"
yeararray[5]="6 years"
yeararray[6]="7 years"
yeararray[7]="8 years"
yeararray[8]="9 years"
yeararray[9]="10 years"
yeararray[10]="11 years"
yeararray[11]="12 years"
yeararray[12]="13 years"
yeararray[13]="14 years"
yeararray[14]="15 years"
yeararray[15]="16 years"
yeararray[16]="17 years"
yeararray[17]="18 years"
yeararray[18]="19 years"
yeararray[19]="20 years"

function setupperlimit(PurchasePrice, DownPayment){

AmtFinanced = PurchasePrice - DownPayment;
if (AmtFinanced < 0) AmtFinanced = 0;
if (AmtFinanced => 0 && AmtFinanced < 9999){
set upper array to 5 so only "1 year" to "6 years" shows in the Loan
Term drop down
}
else if (AmtFinanced => 10000 && AmtFinanced < 14999){
set upper array to 9 so only "1 year" to "10 years" shows in the
Loan Term drop down
}
else if (AmtFinanced => 10000 && AmtFinanced < 14999){
set upper array to 11 so only "1 year" to "12 years" shows in the
Loan Term drop down
}
else if (AmtFinanced => 10000 && AmtFinanced < 14999){
set upper array to 14 so only "1 year" to "15 years" shows in the
Loan Term drop down
}
else{
set upper array to 19 so only "1 year" to "20 years" shows in the
Loan Term drop down
}

}
// -->
</script>

This might be a bad way to approach this but any help would be much
appreciated.

- Mark
 
C

clintonG

VBScript supports a redim statement. Have you ever tried reading the
documentation?
 

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