Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-15-2004, 03:56 PM   PM User | #1
Number_Nineteen
New to the CF scene

 
Join Date: Jul 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Number_Nineteen is an unknown quantity at this point
JScript ASP "for in loop" problem... (not .NET)

I am trying to loop through a Request.Form collection using JScript ASP:

for (objItem in Request.Form) {
counter++;
Response.Write(counter);
try {
//STUFF HERE...
} catch(e) {
Response.Write(e) & "<br>"
}
}

Nothing happens when I run this code. No errors or results. I converted this from my VB version that looks like this.

For each objItem in Request.Form
counter = counter + 1
'STUFF HERE
On Error Resume Next
If Err.number == 0 then
'STUFF HERE
else
Response.Write Err.Description & "<br>"
end if
Next

This works fine. I assume that my objItem in the JScript for in loop is the problem area?

Joe
Number_Nineteen is offline   Reply With Quote
Old 07-15-2004, 08:00 PM   PM User | #2
Roy Sinclair
Senior Coder

 
Join Date: Jun 2002
Location: Wichita
Posts: 3,880
Thanks: 0
Thanked 0 Times in 0 Posts
Roy Sinclair will become famous soon enough
Are you sure you've set JScript as the language for that page?

Also make sure you've turned off the "Show Friendly HTTP error messages" option in IE since that particular option neatly excises all useful error messages leaving only a raw error page (not a "Friendly" option at all IMO).
__________________
Check out the Forum Search. It's the short path to getting great results from this forum.
Roy Sinclair is offline   Reply With Quote
Old 07-15-2004, 08:12 PM   PM User | #3
Number_Nineteen
New to the CF scene

 
Join Date: Jul 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Number_Nineteen is an unknown quantity at this point
Yes... defined JScript. Show frendly is off. The page executes up to the for in loop. So it seems that the value for objItem is null.

No errors. The page finishes loading, but no results are returned.
Number_Nineteen is offline   Reply With Quote
Old 07-15-2004, 08:18 PM   PM User | #4
Roy Sinclair
Senior Coder

 
Join Date: Jun 2002
Location: Wichita
Posts: 3,880
Thanks: 0
Thanked 0 Times in 0 Posts
Roy Sinclair will become famous soon enough
Try this (it uses an enumerator object):

Code:
			<%
			// Create new Enumerator object
			var http = new Enumerator(Request.Form)
			
			// Iterate through the collection
			
			while (!http.atEnd(http))
			    {
			    // Get one item
			    i = http.item()
			    // Show item and it's value
			    Response.Write('Field:' + i + ' = ' + Request.ServerVariables(i) + '<br />')
			    // Get next item
			    http.moveNext()
			    }
			%>
__________________
Check out the Forum Search. It's the short path to getting great results from this forum.
Roy Sinclair is offline   Reply With Quote
Old 07-15-2004, 08:29 PM   PM User | #5
Number_Nineteen
New to the CF scene

 
Join Date: Jul 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Number_Nineteen is an unknown quantity at this point
You are a genius...

I forgot about Enumerator.

Thank you so much!! I was going mad.
Number_Nineteen is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:45 PM.


Advertisement
Log in to turn off these ads.