Solved

Pass Jscript string into Javascript array

Posted on 2007-04-04
6
296 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
Comment Utility
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
Comment Utility
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
Comment Utility
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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Author Comment

by:tremak
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 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

12 Experts available now in Live!

Get 1:1 Help Now