Problem with JScript

Results 1 to 2 of 2

Thread: Problem with JScript

  1. #1
    theBigD Guest

    Default Problem with JScript

    For some reason JavaScript&#039s "for..in" loop, which is supposed to correspond to the VBScript&#039s "for each in..next" loop, won&#039t iterate over the properties of the built-in ASP objects. I&#039ve not had this problem with VBS. Specifically I&#039m trying to populate a <BR>dropdown list with a collection of filenames of a certain type from the current directory.<BR><BR>The JScript code:<BR><BR>var allfiles = Server.CreateObject("Scripting.FileSystemObject"). GetFolder(relPath).Files;<BR>for (var anyfile in allfiles)<BR>{<BR> if (anyfile.Type == "Cascading Style Sheet")<BR> {<BR> anyfile = new String(anyfile.Name);<BR> anyfile = anyfile.substr(0, anyfile.length - 4);<BR> %&#062;&#060;option value="&#060;% =optName %&#062;"&#062;&#060;% =optName %&#062;&#060;%<BR> }<BR>}<BR><BR>fails, whereas the corresonding VBScript:<BR><BR>set allfiles = Server.CreateObject("Scripting.FileSystemObject"). GetFolder(relPath).Files<BR>for each anyfile in allfiles<BR> if anyfile.Type = "Cascading Style Sheet" then<BR> optName = Replace(anyfile.Name, ".css", "")<BR> Response.Write("&#060;option value=" & optName & "&#062;" & optName)<BR> end if<BR>next<BR><BR>works but can&#039t be integrated with my existing JScript. Any idea why this is and if there are any JScript workarounds?<BR><BR>Thanks,<BR>BigD

  2. #2
    Joseph Hatcher Guest

    Default RE: Problem with JScript

    You have<BR><BR>var allfiles =CreateObject("Scripting.FileSystemObject").GetFol der(relPath).Files;<BR>for (var anyfile in allfiles)<BR><BR>Try changinge this line to <BR><BR>for (anyfile in allfiles)<BR><BR>Hope this helps<BR>

Posting Permissions

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