Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 12th, 2005, 11:49 AM
Authorized User
 
Join Date: Jan 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default Populate a popup from an array

Hey all...

I am trying to use a combination of asp and javascript to create a photo album

My asp works great but I am having trouble with the Javascript..

here is the code...notice that I pass the info to a javascript array...cont below...

<%
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set fldr = FSO.GetFolder( Server.MapPath("/folder") )

Dim names
ReDim names( fldr.Files.Count ) ' will be overkill

count = -1
For Each fl In fldr.Files
fname = fl.Name
' get the extension
ext = LCase( Mid( fname, 1 + InStrRev( fname, "." ) ) )
If ext = "jpg" OR ext = "jpeg" OR ext = "gif" Then
count = count + 1
names(count) = fname
%>
<A HREF="#" onClick="show(<%=count%>); return false;">
<IMG SRC="/folder/<%=fname%>" width=150>
</A>
... other html ...
<%
End If
Next

ReDim Preserve names(count) ' chop array to needed size
%>
<SCRIPT Language="JavaScript">
var imgNames = new Array('<%=Join(names,"','")%>');
</SCRIPT>


I can view source and know that the array is being populated...can post an example if necessary...

but how do I pass this info to the popup so that it can display the correct picture from the array in the popup and then add a "back" and "next" buttons to scroll up or down in the array and show the appropriate pictures accordingly

I'd pull my hair out but I don't have any...

 
Old August 13th, 2005, 04:31 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Your show function would look like this:
Code:
function show(ImageIndex)
{
  var sName = imgName[ImageIndex];
  var sHTML = "<html><body><img src=\" + sName + "\"></body></html>";
  var oWin = window.open("");
  var oDoc = oWin.document;
  oDoc.open();
  oDoc.write(sHTML);
  oDoc.close();
  oWin.focus();
}
For next and previous you will have to have code in the new window to link to the relevant image. It would be easier if your show function took the name of the image, instead of writing the count put the image source, and have a second parameter for whetehr a new window is needed or not. This way it can be re-used for both windows.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convering a String Array to an Integer array nkrust C# 9 November 17th, 2010 12:02 PM
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
Populate Array with SQL query string nicoleh Classic ASP Databases 3 July 6th, 2005 02:55 PM
error when sorting an Array of Array nancy VBScript 2 February 17th, 2005 12:57 PM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.