Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    You are a genius...

    I forgot about Enumerator.

    Thank you so much!! I was going mad.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •