Solved

Pass Jscript string into Javascript array

Posted on 2007-04-04
6
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to dynamically set the form action using jQuery.
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