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!

Looping through form fields

Status
Not open for further replies.

peterswan

Programmer
Sep 25, 2002
263
US
Hi,

I'm building a dynamic form in ASP where the contents of the form itself is database driven. What this means is I have no idea what fields will be on the form and what the names of those fields will be. Is there any way I can loop through everything regardless of what's there and insert the values into a database? I know the code in ColdFusion:

<cfloop index=&quot;i&quot; list=&quot;#form.fieldnames#&quot;>
<cfoutput>
#i#&nbsp;&nbsp;#evaluate(&quot;form.&quot;&&quot;#i#&quot;)#
<br>
</cfoutput>

</cfloop>

This gives me the name and the value of every field on the previous page, regardless of what the name is. Is there any such code in ASP that will do this?

Thanks to anyone who can help.

Peter Swanson
 
This will display the form contents onto screen. Easily modified to populate the database.
Code:
<%
For each item in Request.Form
  Response.Write item.Name & &quot;:&quot; & item.Value & &quot;<BR>&quot;
Next
%>
Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
Hi Tony,

It doesn't work. For some reason I'm getting this error (the name of my first text field is &quot;First_Name&quot;):

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'First_Name'
/dev/form_fields_action.asp, line 12

Any ideas?

Peter

 
Hi Tony,

I went to yahoo and typed in &quot;For each item in Request.Form&quot; and found a page that gave me this code:

<%
For each item in Request.Form
Response.Write Item & &quot;: &quot; & Request.Form(Item) & &quot;<BR>&quot; & vbNewLine
Next
%>

and it worked! So you helped me by giving me the first part of the code. I wonder why the rest didn't work.

Anyway, thanks for your help. Problem solved.

Peter
 
Oh, I see your post now.

Thanks Tony, I appreciate the help.

Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top