Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with array statement

Status
Not open for further replies.

squarkman

Technical User
Mar 10, 2008
34
Greetings:
Please see the script below.

This is a photo gallery with changing captions. The photos show and change fine until I added the myCaption Array so I could add captions. After adding the Array, the pictures won't show.

Any help would be greatly appreciated.
Thanks
Rocky
---------------------------------------------------------

// List text captions
var myCaption= new Array(24)
myCaption[00]= "apix001";
myCaption[01]= "apix002";
myCaption[02]= "apix003";
myCaption[03]= "apix004";
myCaption[04]= "apix005";
myCaption[05]= "apix006";
myCaption[06]= "apix007";
myCaption[07]= "apix008";
myCaption[08]= "apix009";
myCaption[09]= "apix010";
myCaption[10]= "apix011";
myCaption[11]= "apix012";
myCaption[12]= "apix013";
myCaption[13]= "apix014";
myCaption[14]= "apix015";
myCaption{15]= "apix016";
myCaption[16]= "apix017";
myCaption[17]= "apix018";
myCaption[18]= "apix019";
myCaption[19]= "apix020";
myCaption[20]= "apix021";
myCaption[21]= "apix022";
myCaption[22]= "apix023";
myCaption[23]= "apix024";
myCaption[24]= "apix025";



// List of image filenames without extension
var myImg= new Array(24)
myImg[00]= "pix001";
myImg[01]= "pix002";
myImg[02]= "pix003";
myImg[03]= "pix004";
myImg[04]= "pix005";
myImg[05]= "pix006";
myImg[06]= "pix007";
myImg[07]= "pix008";
myImg[08]= "pix009";
myImg[09]= "pix010";
myImg[10]= "pix011";
myImg[11]= "pix012";
myImg[12]= "pix013";
myImg[13]= "pix014";
myImg[14]= "pix015";
myImg[15]= "pix016";
myImg[16]= "pix017";
myImg[17]= "pix018";
myImg[18]= "pix019";
myImg[19]= "pix020";
myImg[20]= "pix021";
myImg[21]= "pix022";
myImg[22]= "pix023";
myImg[23]= "pix024";
myImg[24]= "pix025";



// Tell browser where to find the image
myImgSrc = "/dogdaysinla/";

// Tell browser the type of file
myImgEnd = ".jpg"

var i = 0;

// Create function to load image
function loadImg(){
document.imgSrc.src = myImgSrc + myImg + myImgEnd;
document.getElementById('caption') = myCaption;
}

// Create link function to switch image backward
function prev(){
if(i<1){
var l = i+=24
} else {
var l = i-=1;
}
document.imgSrc.src = myImgSrc + myImg[l] + myImgEnd;
document.getElementById('caption') = myCaption[l];
}

// Create link function to switch image forward
function next(){
if(i>23){
var l = i-=24
} else {
var l = i+=1;
}
document.imgSrc.src = myImgSrc + myImg[l] + myImgEnd;
document.getElementById('caption') = myCaption[l];
}

// Load function after page loads
window.onload=loadImg;

-------------------------------------

 
Seriously?

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
wow......

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Hey,
Is there a way to add another argument (if that's the right descriptor) to this snippet such that I end up creating an array of not only pix + count BUT ALSO comment + count?
Thanks in advance. Would that be called a two-dimensional array??
R
--------snippet------------
var myImg= new Array(), limit = 25;
var count;
for (var mi=0; mi<limit; mi++)
{
count = mi + 1;
if (count < 10)
{
count = '00' + count;
}
else if (count < 100)
{
count = '0' + count;
}
myImg[mi] = 'pix' + count;
-------------------------
 
Two dimensional arrays are not explicitly declared anyhow in JS. You can have an array of anything you like... including an array of arrays.

So to store a count, an image name and a comment all in one array you could have something like:
Code:
var mainArray = new Array();
mainArray[0] = [1, "mypic1.gif", "Me and the missus on the beach"];
mainArray[1] = [2, "mypic2.gif", "Sunset at the Taj Mahal"];
And so on and so forth.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
The URL I provided does something like this, but uses objects that contain an image URL and a caption. Just grab the source from that.

Lee
 
Dwafthrower,
Thanks, but what I meant was not to fill it in manually as you have done in your last example, but automated with two variables. Would it be done something like this?

myImg[mi] = 'pix' + count, 'comment' + count;

--------------
var myImg= new Array(), limit = 25;
var count;
for (var mi=0; mi<limit; mi++)
{
count = mi + 1;
if (count < 10)
{
count = '00' + count;
}
else if (count < 100)
{
count = '0' + count;
}
myImg[mi] = 'pix' + count;
 
No, it would be done as per my example, storing an array as the value, using array notation.

Cut between the lines:
-----------------------------------------------
myImg[mi] = ['pix' + count, 'comment' + count];
-----------------------------------------------

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
One final question.

I am going to make it so that the owner of the site can open a hidden form on his site which will allow him to upload an image to his site and add caption and image info to the .js file on his site.

Can this all be done with php? Any details offered would be greatly appreciated.

Rocky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top