-
Hello,
How can I pass an array from one page to the next.
Eg.
In page 1 I have
<%
dim array1(100)
array1(1) = "hello"
array1(2) = "word"
%>
I now submit/post this form to page2 where I want to do something like
<%
dim array2(100)
array2 = request.form array1
response.write array2(1)
response.write array2(2)
%>
Which must results in - "helloworld".
Can it be done.
Thanks,
T
-
You will need to pass the values to the next page us a FORM or by putting the values in the QueryString. Just assign the values in your form to have the same name.
Example:
Code:
<form action="page2.asp" method="get">
<%
dim array1(100)
array1(1) = "hello"
array1(2) = "word"
For i = LBound(array1) to UBound(array1)
%>
<input type="hidden" name="array1" value="<%=array(i)%>">
<%
Next
%>
</form>
page2.asp should have the following code
Code:
<%
dim array1(100)
For i = 1 to Request.QueryString("array1").Count
array(i - 1) = Request.QueryString("array1")(i)
Next
%>
This should take care of it, for an array of pre determined size. If the array is dynamic you will need to ReDim it accordingly.
Also remember that VBScript arrays are zero based by default.
-
Thanks kkolstad,
It works great!!
T
-
Another option will be push store the array in a session or application wide variable.
-
yep works real well I did this
Code:
<%for p = 0 to ubound(strSt)%>
<input type="hidden" name="ArrayState" value="<%=strSt(p)%>">
<%next%>
<%for d = 0 to ubound(strSt)%>
<input type="hidden" name="ArrayTotal" value="<%=strTl(d)%>">
<%next%>