In Part 1, we looked at how to create an array and encode it for passing it to another web page. In this part of the article, we are going to look at how to receive this information and decode it back into an array.
When variables are passed from one ASP page to another, either via the querystring or a form, when multiple variables have the same name, the
Request object creates a comma-delimited list containing all of the values that have the same name. For example, if you call an ASP page with the following querystring:
and then print out the value of
SomePage.asp, you will receive the following output:
Barney, Alexis, Spud
ReceiveArray.asp, we need to begin with reading in the
WeekDays variable, that was passed in via either the querystring or a form. Next, we need to create an array variable (
aWeekDays), and use
split to populate this array with the comma-delimited list sent from
CreateArray.asp. Let's look at some code!
Isn't this neat? We've just created an array named
ReceiveArray.asp that is nearly identical to the
aWeekDays array we created in
CreateArray.asp! The only discrepency between the two is that the
aWeekDays array in
ReceiveArray.asp contains a space as the first character for all elements but the first. This is because the comma-delimited list represented by
strWeekDays contains a space after each comma. So, to fix this, we need to iterate through the array,
Trimming each element. The following code will do just that:
Finally, we can print out the contents of the
aWeekDays array if we'd like. Just need to iterate through each element in the array.
Well, that's all there is to it! I hope you learned something new! :)
CreateArray.aspin text format
ReceiveArray.aspin text format