1

I get the error message syntax error missing ; before statement at "var galleryarray=new Array();" . "\n"; here is the php code

function returnimages($dirname=".") {
    $pattern="\.(jpg|jpeg|png|gif|bmp)$";
    $files = array();$curimage=0;
    if($handle = opendir($dirname)) {
        while(false !== ($file = readdir($handle))){
            if(eregi($pattern, $file)){
                echo 'galleryarray[' . $curimage .']=["' . $file . '"];' . "\n";
                $curimage++;
            }
        }
    closedir($handle);
    }
    return($files);
}
echo "var galleryarray=new Array();" . "\n";
returnimages();

and here is the javascript:

var galleryarray=new Array(); 
var curimg=0
function rotateimages(){
    document.getElementById("slideshow").setAttribute("src", "slideshow_images/"+galleryarray[curimg])
    curimg=(curimg<galleryarray.length-1)? curimg+1 : 0
}
window.onload=function(){
    setInterval("rotateimages()", 2500)
}

i just don't see my mistake any help with this problem would be appreciated

klein

1
  • var curimg=0 miss a semicolumn at the end Commented Jan 29, 2015 at 8:21

1 Answer 1

1

Replace your below line:

echo "var galleryarray=new Array();" . "\n";

with the following line:

echo "<script>var galleryarray=new Array();</script>";

You are adding a JS code without script tag so you need to add this tag.

EDITED:

echo 'galleryarray[' . $curimage .']=["' . $file . '"];' . "\n";

You also have error in the above line replace it with the below line:

echo '<script>galleryarray["' . $curimage .'"]=["' . $file . '"];</script>';
Sign up to request clarification or add additional context in comments.

8 Comments

thanks for the help code lover but now I get the error msg syntax error; expected statement got <
@kleinmorgan replace double quota " with single quota ' and then try. hope this will work
I have tried replacing the double quotes with singles but now I get
syntax error missing; before statement echo 'galleryarray[' . $curimage .']=["' . $file . '"];' . "\n";
thanks marco mura but adding the semicolumn does not bring the rest of the images. the gallery is still getting stuck on the first image
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.