View Full Version : JScript ASP "for in loop" problem... (not .NET)

07-15-2004, 03:56 PM
I am trying to loop through a Request.Form collection using JScript ASP:

for (objItem in Request.Form) {
try {
} 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
On Error Resume Next
If Err.number == 0 then
Response.Write Err.Description & "<br>"
end if

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


Roy Sinclair
07-15-2004, 08:00 PM
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).

07-15-2004, 08:12 PM
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.

Roy Sinclair
07-15-2004, 08:18 PM
Try this (it uses an enumerator object):

// 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

07-15-2004, 08:29 PM
I forgot about Enumerator.

Thank you so much!! I was going mad.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum