Microsoft KB Archive/198808

= How To Post a Dynamic String Array from the Client to an ASP =

Article ID: 198808

Article Last Modified on 7/16/2004

-

APPLIES TO


 * Microsoft Active Server Pages 4.0
 * Microsoft Visual InterDev 6.0 Standard Edition
 * Microsoft Internet Information Server 4.0
 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q198808



SUMMARY
This article describes how to submit a dynamic string array from the client to an ASP page. Normally, if you have a fixed-length string array for submitting this to the server, you can create a form with some hidden fields in it, whose value is set to different strings in the array. The number of hidden fields defined in the form will be equal to the number of elements in the array.

However, if the number of elements in the array is not known beforehand (that is, if you are using a dynamic array), you won't be able to use a pre-defined form because the number of hidden fields to be used is unknown while coding the HTML page.

This example shows how to create a form dynamically depending on the number of elements in the array and then submit the data to the server.



MORE INFORMATION
 Create a new ASP.  Copy and paste this code into it. Save the file as "try.asp" and preview it in a browser: <%@ Language=VBScript %>       <% If Request.Form <>"" Then For each intNumItems in Request.Form Response.Write Request.Form(intNumItems) & "" Next Response.Write "" End if%> 

<FORM NAME="MyForm"> Enter the number of elements in the array: </B> <INPUT TYPE="TEXT" NAME="numelements" VALUE="5"> </FORM>  <INPUT TYPE="BUTTON" NAME="cmdButton" VALUE="Send To Server">

<Script Language="VBSCRIPT"> Dim MyArray ReDim MyArray(5)

Sub cmdButton_onClick intNumItems=Cint(Document.MyForm.numelements.value) If intNumItems <> 0 Then ReDim MyArray(intNumItems) End if

'Fill in the array with the string of the word VALUE plus the counter number For i = 0 to intNumItems MyArray(i) = "Value " & i Next

Dim i i = Ubound(MyArray) a = "<FORM NAME=" & chr(34) & "TempForm" & chr(34) & " ACTION=try.asp METHOD=POST>" For intNumItems = 1 to i   a = a & "<INPUT TYPE=" & chr(34) & "HIDDEN" & chr(34) & "Name=" & chr(34) & _ "item" & intNumItems & chr(34) & "Value =" & chr(34) & MyArray(intNumItems) & chr(34) & "> " Next a = a & "</FORM>" Document.Write a TempForm.Submit End Sub

</Script> </BODY> </HTML> </li></ol>

Keywords: kbhowto kbcodesnippet KB198808

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.