How to pass an array as parameter via URL?

Posted on 2009-02-20
Last Modified: 2012-06-27
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

Question by:toyman61
    LVL 15

    Expert Comment

    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.
    LVL 28

    Expert Comment

    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.

    Author Comment

    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.. :-)


    LVL 28

    Expert Comment

    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


    Author Comment

    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!!!

    LVL 28

    Expert Comment

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

    Hmm, I did post sample code, see above.

    Author Comment

    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.. :-)

    LVL 28

    Accepted Solution

    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


    Author Closing Comment

    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

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now