• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3119
  • Last Modified:

How to pass an array as parameter via URL?

How do I most efficiently transfers the contents of an array via URL?. I am using VBScript as my "language".

See the attached code snippet.

One solution is to put all the array elements together into a string variable, and then decode this string variable in the receiving routine.

The file '08start.asp' is started, and then I dobleclick on the URL named 'Returnlink'. This calls the '08test.asp' and the values of the array is then displayed. So the methodology works, but is this the best way to do it ?

Code snippets is welcome. :-)
The contents of '08start.asp":
file = "08test.asp"
Returnlink(0) = "URL1"
Returnlink(1) = "URL2"
Returnlink(2) = "URL3"
Returnlink(3) = "URL4"
Returnlink(4) = "URL5"
Returnlink(5) = "URL6"
Returlinks = Returnlink(0) & "@" & _
             Returnlink(1) & "@" & _
             Returnlink(2) & "@" & _
             Returnlink(3) & "@" & _
             Returnlink(4) & "@" & _
             Returnlink(5) & "@"   
NoOfElements = 3
response.write "<a href="& chr(34) & file & "?RETUR=" & Returnlinks &  "&COUNTS=" & NoOfElements & chr(34) & ">Returnlink</a>"
The contents of '08start.asp":
dim Returnlink(5)
ReturnLinks = Request("RETUR")
NoOfElements = Request("COUNTS")
 for i = 1 to NoOfElements+1
  iLength = LEN(Returnlinks)
  index1 = InStr(ReturnLinks,"@")
   if index1 > 0 then
    Returnlink(i-1) = Left(Returnlinks,index1-1)
    Returnlinks = Right(Returnlinks,iLength-index)
   end if 
    if InStr(Returnlinks,"@") = 0 then
     Returnlink(i-2) = Returnlinks
     response.write "<br> Returnlink(" & chr((i-2)+48) & ")=" & Returnlink(i-2) & "<br>"  
    end if

Open in new window

  • 4
  • 4
1 Solution
That depends on the client side you pass an array to. Foe example you can specify RETUR parameter many times (one for each array element), CGI will recognize that.
I am not sure what you are trying to do.

ASP is most of the time used in combination with a database. Things are being stored into and retrieved from a database. The id's of the records in the database tables are then very handy as a reference to certain values.

In practice I work most with forms and accustom my way of working to how forms work. Like a list of checkboxes generated from a database

Do While Not oRS.EOF
    <input type="checkbox" name="yourpreference" value="<%=oRS("id")%>"> name: <%=oRS("name")%><br>

When the user submits this form it will generate a sort of array of all choices checked by the user. It uses however the id's of records as a reference. If in the next page it is needed to give meaning to the id's selected by the user, then the solution is to take a look in the database to find out what these id's refer to.

There are situations thinkable when it is actually needed to pass the real values (and not just the id's) from one page to another: when communicating with a totally different site and database. That is often done with XML-requests (SOAP or XML-RPC).

Well. Maybe I just do not really understand your question.
toyman61Author Commented:
mish33 and sybe:

I'm setting up an intranet service in our company. One of the tasks is to display subfolders and files in a given folder in the Windows file system of the server. I get the information about subfolders and files and display them as links.

I have attached a file with the code used.

The code works nearly perfect, but I have one problem:

1) First I'm trying to list folders in folderA.
2) Folder A contains:
    - SubFolder1
    - SubFolder2
   -  FileA
   -  FileB
   -  FileC

 3) SubFolder1 contains:
     - SubFolder3
     - SubFolder4

 4) SubFolder3 contains:
     - FileD
     - FileE
     - FileF

When I call subfolder1 then Returnlink contains the value of folderA.       ==> OK
When I call subfolder3 then Returnlink contains the value of subfolder1. ==> OK

When I hit the "Back"-link in the listing page of subfolder3 I go back to subfolder1, but the "Back"-link is not shown on that page...

I wonder if I should build a "returnlink-chain" with the index number in element no. 0 (zero), or is there any other solution?

If the folder tree is deeper than 3 levels I have a serious problem.. :-)


Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Actually with the help of a recursive function it is not so hard to write out the complete folder/file tree.

What I would do is to get the whole tree on a single page and then have just like in Windows Explorer some "+" and "-" signs so people could close or open a folder. But that would work with javascript on the client.

I'll post some sample code here. No images, but clicking on the foldername will open/close the folder.
function OpenCloseFolderlist(oLink) {
	if (oLink.getAttribute('open') == '0') {
		oLink.setAttribute('open', 1)
	} else {
		oLink.setAttribute('open', 0)
WriteFolderTree "D:\Inetpub\wwwroot", 0
Sub WriteFolderTree(ByVal sStartFolder, ByVal iDepth)
	Response.write "<table border=""1"" style=""display:" & IIF(iDepth=0,"","none") & """>"
	Dim oFS, oFolder, oSubFolder, oSubFolders
	Dim oFiles, oFile
	Set oFS = CreateObject("Scripting.FileSystemObject")
	Set oFolder = oFS.GetFolder(sStartFolder)
	Set oSubFolders = oFolder.SubFolders
	For Each oSubFolder in oSubFolders
		Response.write "<tr><td><a href=""#"" open=""0"" onclick=""OpenCloseFolderlist(this);"">" & RepeatString(3*iDepth, "&nbsp;") & oSubFolder.Name
		WriteFolderTree sStartFolder & "\" & oSubFolder.Name, iDepth + 1
		Response.write "</td></tr>" & CHR(13)
	Set oFiles = oFolder.Files
	For Each oFile in oFiles
		Response.write "<tr><td>" & RepeatString(3*iDepth, "&nbsp;") & "&nbsp;&nbsp;" & oFile.Name & "</td></tr>"
	Set oSubFolders = Nothing
	Set oFiles = Nothing
	Set oFolder = Nothing
	Set oFS = Nothing
	Response.write "</table>"
End Sub
Function RepeatString(ByVal i, ByVal s)
    RepeatString = REPLACE(SPACE(i), " ", s)
End Function
Function IIf(bCondition, TrueValue, FalseValue)
	IIf = FalseValue
	If bCondition Then IIf = TrueValue
End Function

Open in new window

toyman61Author Commented:
sybe: Javascript on the client is no problem, as far as I know. I think your suggestion using '+' and '-'  to open/close the folders seems very interesting, so if you have any code on it I would be very interested.

Maybe the approach of having it all on the same web-page is a better solution than mine? I will consider doing it that way. Thanks!!!

> so if you have any code on it I would be very interested.

Hmm, I did post sample code, see above.
toyman61Author Commented:
But no '+' and '-' sign in that code, or ??
I'm not very good at Javascript, but it seems that I would have to learn it ...sometime.. :-)

Well, it is about dinner time here, so I'll give you a quick one. The could be shorter, but this way it makes hopefully more sense to you. Haven't tested it.
function ToggleImage(oImage) {
    if(oImage.src=='plus.gif') {
        oImage.src = 'minus.gif';
    } else {
        oImage.src = 'plus.gif';
<img src="plus.gif" onclick="ToggleImage(this);">

Open in new window

toyman61Author Commented:
sybe: I have played around with your suggestions and code snippets, and I think I have found what I was looking for. So I'll give you the points for this, but I may come back to ask some more questions.. .:-)

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now