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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP get loop array HTML fields 1

Status
Not open for further replies.

iranor

Programmer
Jun 17, 2004
174
CA
Hi, I have some fields dynamically generated and I don't know how many. Let say that I create 10 fields on an HTML page with asp:

<input type="text" name="Field[1]">
<input type="text" name="Field[2]">
<input type="text" name="Field[3]">
...

Using PHP, I could loop on the Field value and get each of them, but it doesn't seems to work in ASP using QueryString...

I tried
For Each mString In Request.QueryString("Field")
Response.Write(mString)
Next
but it doesn't outputs anything.

Any hing will be much appreciated.
 
Try...

Code:
For Each mString in Request.QueryString
  Response.Write(mString & " = " & Request.QueryString(mString) & "<br />")
Next

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Ah, I didn't tough about that one... And i'm lucky, that Field is the only field that I got!

Thanks :)
 
>> i'm lucky

That may be true. However, if you would have had additional fields and only wanted certain ones, you could get a little more creative to filter out the unwanted ones. Here's one method.

<input type="text" name="Field[1]">
<input type="text" name="Field[2]">
<input type="text" name="Field[3]">
<input type="text" name="SomethingElse">

Code:
<%
For Each mString in Request.QueryString
    If Instr(1, mString, "Field[") > 0 And Right(mString, 1) = "]" Then
        Response.Write(mString & " = " & Request.QueryString(mString) & "<br />")
    End if
Next

%>

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks, the one you gave me earlier will do the job, but i'll note that one if I ever need it ;) I've been coding PHP for a long time, and i'm trying ASP now, there's a lot of differences ^^
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top