Jump to content

Undefined global variable issue


twoweektrial

Recommended Posts

I have a slideshow I've been working on for a few hours, and for some reason I can't seem to access global variables

 

Here's the code:

// Slideshow processor

 

var images = new Array();

var current = 0;

 

function setup_gallery()

{

if (window.XMLHttpRequest)

{

xml=new XMLHttpRequest();

}

else

{

xml=new ActiveXObject("Microsoft.XMLHTTP");

}

 

xml.onreadystatechange=function()

{

if (xml.readyState==4 && xml.status==200)

{

    images = xml.responseText.split(" ");

}

}

xml.open("GET", "/inc/image_grabber.php", true);

xml.send();

 

$("ss_first").onClick = first();

$("ss_last").onClick = last();

$("ss_next").onClick = next();

$("ss_previous").onClick = previous();

 

change_image(current);

}

 

function change_image(next)

{

var e = $("picture_frame");

e.href = images[next];

}

 

//The following four functions modify 'current' and then change the image

function first()

{

current = 0;

change_image(current);

}

 

function last()

{

current = images.length - 1;

change_image(current);

}

 

function next()

{

current++;

if(current >= images.length)

{

current = 0;

}

change_image(current);

}

 

function previous()

{

current--;

if(current <= 0)

{

current = images.length + 1;

}

change_image(current);

}

 

This is using a php page that returns a string of image names separated by spaces.

When I run the code, images[0] is undefined.

 

I may have left out something valuable, but I'm a little frazzled, so thanks in advance for your help.

Link to comment
https://forums.phpfreaks.com/topic/203571-undefined-global-variable-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.