Solved

Pass Jscript string into Javascript array

Posted on 2007-04-04
6
301 Views
Last Modified: 2010-04-16
I would like to somehow get the file names loaded in the string strfilenames from the jscript portion of a page below

<% @language = "jScript"%>
<%
var fso = new ActiveXObject("Scripting.FileSystemObject")
var fpath = fso.getFolder(Server.MapPath("/prodimages"))
var fc = new Enumerator(fpath.files)
var strfilenames=new String("")
var strl=new String("")
var sLoc=new String("")

for(;!fc.atEnd();fc.moveNext()){
strfilenames=strfilenames+fc.item()
}
%>

Into the array loaded in the Javascript snippet below.

<script language='JavaScript'
import java.io.File>
var mypix = new Array()
var mypixNames = new Array()

mypixNames = ["000_0001.jpg", "000_0008.jpg", "000_0012.jpg", "000_0013.jpg", "000_0015.jpg", "000_0016.jpg", "000_0017.jpg"]
var iTotalNumImages = 7;
var iCounter = 0;
var iTimer;
var blnWaiting = false;
var blnAutoStart = false;
var blnRepeat = true;
var blnTransOn = false;


function changeImages() {
for (int i = 0; i < list.length; i++)  {

    mypix[0].src = mypixNames[0];
    mypix[1].src = mypixNames[1];
    SetControls();

    if (blnAutoStart == true)
        iTimer = setInterval('doTrans(1)', 1000);

}

This is some javascript code I purchased to produce a slide show and what I would like is for the Javascript to identify all files in a folder on my site that have .jpg file types and load the array mypixNames in the Javascript code.

My questions are

1.) How can I pass the string from the Jscript to the Javascript code and load the string into the array mypixNames

2.) In the loop that builds the string strFileNames, how can I bypass files that don't have the .jpg file type.

Since this is keeping me from billing a client (meaning no money for me), I'm giving max points for answers and not just links to sample code.
0
Comment
Question by:tremak
  • 4
  • 2
6 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 18854930
Change

for(;!fc.atEnd();fc.moveNext()){
strfilenames=strfilenames+fc.item()
}

to

for(;!fc.atEnd();fc.moveNext()){
      if (fso.GetExtensionName(fc.item()).toLowerCase() == "jpg"){
            strfilenames = strfilenames + '", "' + fc.item();
      }
}
strfilenames = strfilenames.substring(3) + '"';

and change

mypixNames = ["000_0001.jpg", "000_0008.jpg", "000_0012.jpg", "000_0013.jpg", "000_0015.jpg", "000_0016.jpg", "000_0017.jpg"]

to

mypixNames = [<%=strfilenames%>]
0
 

Author Comment

by:tremak
ID: 18856826
I'm extremely new to javascript and jscript.

Isn't my variable strfilenames a jscript variable while your suggested code

mypixNames = [<%=strfilenames%>]

appears to treat the variable strfilenames as an asp.net variable.
0
 
LVL 58

Expert Comment

by:amit_g
ID: 18859515
Anything between <% and %> is executed on server. So strfilenames is server variable and that is why <%= %. is used to output it to get to the client side javascript.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:tremak
ID: 18859773
I'll try this when I get home and let you know.
0
 

Author Comment

by:tremak
ID: 18869777
In the code below, how can I change it so only the file name and extension are added to the string.

For example,

Instead of D:\hosting\tjrfsstesting\prodimages\000_0001.jpg, all I need added to the string is 000_0001.jpg.



for(;!fc.atEnd();fc.moveNext()){
      if (fso.GetExtensionName(fc.item()).toLowerCase() == "jpg"){
            strfilenames = strfilenames + '", "' + fc.item();
      }
}
strfilenames = strfilenames.substring(3) + '"';
0
 

Author Comment

by:tremak
ID: 18869806
Please disregard my previous question.

I ended up finding the answer in another E-E posting.

Here's what I did

for(;!fc.atEnd();fc.moveNext()){
      if (fso.GetExtensionName(fc.item()).toLowerCase() == "jpg"){
                  fn = fc.item()
            strfilenames = strfilenames + '", "' + fso.GetFileName(fn);
      }
}
Response.write(strfilenames)
strfilenames = strfilenames.substring(3) + '"';

Thanks for the help.

Accepting amit_g: answer
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now