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!

For each... is scrambling requested items from form 1

Status
Not open for further replies.

spook007

Programmer
May 22, 2002
259
US
I have a form with text box, radio button and text area controls. I'm submitting the results to a script that is then displaying the individual items and their results from a loop. The code on the script is as follows:

<%
'display individual items from form
for each collItem in Request.Form
Response.Write(collItem&&quot; = &quot;)
Response.Write(Request.form(collItem)&&quot;<br>&quot;)
next

'display entire form results
Response.Write(Request.form&&quot;<br>&quot;)
%>

When I view the results, the results are scrambled and out of order. If the first 6 controls in my form were first name, last name, address, city, state, zip. My results would return:

first name = George
address = 452 Washington Ave
last name = Williams
city = Springville
Submit = Submit
state = OR
zip = 12345

If I view the string of items that was sent it displays in the correct order:

first+name=first+name&last+name=last+name&address=address&city=city&state=state&zip=zip&Submit=Submit

Why the difference? Why does it scramble it like that and how can I fix it so that the results are displayed in order?

 
Spook,

I had a similar issue and could never get the same set of results back in the same order when using the for next loop for the form collection. I eventually ended up individually assigning the values to specific variables on the page. Perhaps not the most elegant solution, but it saved me some headaches.

Why it does this? Don't know, was just informed by another friend of mine that this is a funky thing in ASP. Insanity is merely a state of mind while crazy people have a mind of their own.
 
This is not actually just an ASP problem. The form collection is set up as a Hash table, so you can sometimnes get the items in order if there is a small number of them, but once you start getting a larger number of items in the form than you are almost guaranteed to not get them in order. Using querystring may help keep the order (as you displayed above), or you could create second fields with the same name and an order number sp that for each request.form you would receive not just the user value but the number to specify what order it should be in.

-Tarwn &quot;If you eat a live toad first thing in the morning, nothing worse will happen all day long.&quot; - California saying
&quot;To you or the toad&quot; - Niven's restatement of California saying
&quot;-well most of the time anyway...&quot; - programmers caveat to Niven's restatement of California saying
(The Wiz Biz - Ri
 
Thanks, Tarwn. Had never actually heard of a Hash table, so I had to look it up and now I am feeling a little more educated today. :) Insanity is merely a state of mind while crazy people have a mind of their own.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top