Click to See Complete Forum and Search --> : loop through values from a form
esthera
11-07-2004, 09:13 AM
I use the following code to loop through values of a form:
For Each obj in request.form
body = body & obj & " : " & request.form(obj) & vbCrLf
Next
How can I make tit that it gets the values from the form in the same order as they are on the form?
chrismartz
11-07-2004, 09:23 AM
you could request.form piece by piece....but that would be the hard way i'm sure....i don't know of any other way.
esthera
11-07-2004, 09:27 AM
it's a huge form. Any easier way?
chrismartz
11-07-2004, 09:37 AM
try:
<%
'loop through the request.form fields and output the information
For Each field In Request.Form
%>
<%= field %><br />
<%= request.form(field) %>
<% next %>
esthera
11-07-2004, 09:45 AM
that's what I'm doing. It isn't in order.
chrismartz
11-07-2004, 09:46 AM
hm....i tried it and it worked :confused:
chrismartz
11-07-2004, 09:50 AM
you have given all your form elements a name and value, correct?
esthera
11-07-2004, 09:54 AM
yes. I get the name and value but just not in the same order as it is in the form.
russell
11-07-2004, 03:48 PM
There is no way to gurantee or predict the order that the form values will be interpreted in a for each loop. Since it's a large form, I'd put all the names of the form elements in an array and do domething like this:
Dim arElements
Dim i
arElements = Array("First", "Last", "DOB", "SSN", "CreditCard", "CCNumber", "totalOrder")
For i = 0 to ubound(arElements)
body = body & arElements(i) & " : " & request.form(arElements(i))
Next