Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically creating form items and passing the info to other pages 1

Status
Not open for further replies.

sgore

Programmer
Jul 22, 2001
30
CA
I have a page that generates form items on the fly and appends my loopcounter to each input name

i.e. <input type=&quot;text&quot; name=&quot;name<%=loopcounter%>&quot;>

Can anyone tell me how I can access this form information on a seperate page? More specifically since this for loop generates <input> items on the fly I cannot hard code the recieving pages CStr(Request())information. It will need to be created on the fly as well.

Page 1
<% Dim count
count=3
FOR i = 1 to count %>
<tr>
<td width=&quot;22%&quot;>
<div align=&quot;right&quot;><b>Full Name:</b></div>
</td>
<td width=&quot;27%&quot;>
<input type=&quot;text&quot; name=&quot;name<%=i%>&quot;>
</td>
<td width=&quot;26%&quot;>
<div align=&quot;right&quot;><b>address:</b></div>
</td>
<td width=&quot;25%&quot;>
<input type=&quot;text&quot; name=&quot;address<%=i%>&quot;>
</td>
</tr>
<% NEXT %>

I thought about using a for loop again but I run into this problem. I am not sure how to use the loopcounter with a variable. Can someone show me how to achieve this?

Page 2
<%
for i = 1 to count
name[how do I append i here] = CStr(Request(&quot;name[how do I append i here]&quot;))
next
%>

I hope this makes sense


 
Two ways:
First Way (Suggested): Go through each item in the Request object, checking if the a subString of the object is equal to your variable name. Store these values in an array or whatever.
Code:
<%
Dim results()
Dim index

index = 0
For Each SubKey in Request.Form(&quot;name&quot;)
   ReDim Preserve results(index + 1)
   index = index + 1
   results(index) = Request.Form(&quot;name&quot;)(index)
Next
%>

Second Way (modification to your code):
Page 2
Code:
<%
Dim name()
Dim count

count = Request.Form.Count
for i = 1 to count
   ReDim Preserve name(i)
   name(i) = CStr(Request(&quot;name&quot; & i))
next
%>

Wushutwist
 
That worked out great!!

Thanks so much for your help,
sgore
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top