Solved

Pass Jscript string into Javascript array

Posted on 2007-04-04
6
307 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…
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 …

808 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