Solved

Pass Jscript string into Javascript array

Posted on 2007-04-04
6
306 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

816 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

11 Experts available now in Live!

Get 1:1 Help Now