EDIT: I'm having a new issue with this. Next() was changed to the following:
var nextClicked = 0;
function next()
{
nextClicked = 1;
cycler();
}
I have also tried:
var nextClicked = 0;
function next()
{
nextClicked++;
cycler();
}
In both cases, when the Next function fires, the change in the nextClicked variable value never occurs. I have watched the line being read in the Chrome Inspector, but the variable value never changes. I am at a loss. And I have not found any references to this in searching (although someone with more familiarity with past questions may have more luck). Can anyone explain this bizarre behavior? Thank you!
EDIT: Removing the parenthesis, as recommended below, solved the problem of the image cycling failing to execute, thank you very much.
This is a JavaScript image slide show. Each image displays for 5 seconds, then the next is displayed. When the final image is reached, the cycle restarts. Everything was working perfectly when I had this code written out in sequence:
<script type="text/javascript>
var clicked = 0; // repeatedly clicking slide show button disrupts image cycling, trap this error.
function cycle()
{
clicked += 1;
if (clicked > 1) return;
cycler();
}
function cycler()
{
setTimeout(image1, 0000);
setTimeout(image2, 5000);
setTimeout(image3, 10000);
setTimeout(image4, 15000);
setTimeout(image5, 20000);
setTimeout(image6, 25000);
setTimeout(image7, 30000);
setTimeout(image8, 35000);
setTimeout(image9, 40000);
}
var navImages = '<br><br><img style="float:left;" src="back.png" alt="Previous Image" width="160" height="80" /><img style="float:right;" src="next.png" alt="Next Image" width="160" height="80" />';
function image1()
{
document.getElementById("cycle").innerHTML = '<img src="floating_city.jpg" alt="Floating City" width="800" height="532" /><br><div>Floating City - Created in Voyager</div>' + navImages;
document.getElementById("cycle").scrollIntoView();
}
function image2() {document.getElementById("cycle").innerHTML = '<img src="frozen_lake.jpg" alt="Frozen Lake" width="800" height="532" /><br><div>Frozen Lake with Alien Antenna - Created in Voyager</div>' + navImages};
function image3() {document.getElementById("cycle").innerHTML = '<img src="paradise_peak.jpg" alt="Paradies Peak" width="800" height="532" /><br><div>Paradise Peak - Created in Voyager</div>' + navImages};
function image4() {document.getElementById("cycle").innerHTML = '<img src="northern_moon.jpg" alt="Northern Moon" width="800" height="532" /><br><div>Northern Moon - Created in MojoWorld</div>' + navImages};
function image5() {document.getElementById("cycle").innerHTML = '<img src="woman_on_alien_beach.jpg" alt="Woman on Alien Beach" width="800" height="532" /><br><div>Woman on Alien Beach - Landscape Created in Voyager - Figure Created in Poser</div>' + navImages};
function image6() {document.getElementById("cycle").innerHTML = '<img src="mount_vanilla.jpg" alt="mount_vanilla" width="800" height="532" /><div>Mount Vanilla - Created in Voyager</div>' + navImages};
function image7() {document.getElementById("cycle").innerHTML = '<img src="blue_orbs.jpg" alt="Blue Orbs" width="800" height="532" /><div>Blue Orbs - Created in Bryce</div>' + navImages};
function image8() {document.getElementById("cycle").innerHTML = '<img src="ufo_city.jpg" alt="UFO City" width="800" height="532" /><div>UFO Invasion - Created in Bryce - Pyrotechnics Created in Particle Illusion</div>' + navImages};
function image9() {cycler()}; // Create infinite loop (without crashing browser).
</script>
Then, I tried to add code for the Back and Next buttons. This basically required that code be inserted after every setTimeout line, so that the image# function could be moved to the next (or previous) image# function, the timeout reset, and the cycler() function exited. All that code seemed redundant, so I placed the code in a loop.
<script type="text/javascript">
<!--
var clicked = 0;
var imageNumber = 1;
var mSeconds = 0;
var nextClicked = 0;
var prevClicked = 0;
var callFunction = '';
function cycle()
{
clicked += 1; // repeatedly clicking slide show button disrupts image cycling, trap this error.
if (clicked > 1) return;
cycler();
}
function cycler()
{
for (i = 1; i < 10; i++)
{
if (nextClicked == 1)
{
imageNumber++;
mSeconds = 0;
window['image' + imageNumber]();
}
if (prevClicked == 1)
{
imageNumber--;
mSeconds = 0;
window['image' + imageNumber]();
}
callFunction = 'image' + imageNumber;
setTimeout(window[callFunction](), mSeconds); // call image# function, set time
imageNumber += 1;
mSeconds += 5000;
if (imageNumber == 9) {imageNumber = 1};
if (mSeconds == 45000) {mSeconds = 0};
}
}
var navImages = '<br><br><img style="float:left;" src="back.png" alt="Previous Image" width="160" height="80" onClick="prev()" /><img style="float:right;" src="next.png" alt="Next Image" width="160" height="80" onClick="next()" />';
function image1()
{
document.getElementById("cycle").innerHTML = '<img src="floating_city.jpg" alt="Floating City" width="800" height="532" /><br><div>Floating City - Created in Voyager</div>' + navImages;
document.getElementById("cycle").scrollIntoView();
}
function image2() {document.getElementById("cycle").innerHTML = '<img src="frozen_lake.jpg" alt="Frozen Lake" width="800" height="532" /><br><div>Frozen Lake with Alien Antenna - Created in Voyager</div>' + navImages};
function image3() {document.getElementById("cycle").innerHTML = '<img src="paradise_peak.jpg" alt="Paradies Peak" width="800" height="532" /><br><div>Paradise Peak - Created in Voyager</div>' + navImages};
function image4() {document.getElementById("cycle").innerHTML = '<img src="northern_moon.jpg" alt="Northern Moon" width="800" height="532" /><br><div>Northern Moon - Created in MojoWorld</div>' + navImages};
function image5() {document.getElementById("cycle").innerHTML = '<img src="woman_on_alien_beach.jpg" alt="Woman on Alien Beach" width="800" height="532" /><br><div>Woman on Alien Beach - Landscape Created in Voyager - Figure Created in Poser</div>' + navImages};
function image6() {document.getElementById("cycle").innerHTML = '<img src="mount_vanilla.jpg" alt="mount_vanilla" width="800" height="532" /><div>Mount Vanilla - Created in Voyager</div>' + navImages};
function image7() {document.getElementById("cycle").innerHTML = '<img src="blue_orbs.jpg" alt="Blue Orbs" width="800" height="532" /><div>Blue Orbs - Created in Bryce</div>' + navImages};
function image8() {document.getElementById("cycle").innerHTML = '<img src="ufo_city.jpg" alt="UFO City" width="800" height="532" /><div>UFO Invasion - Created in Bryce - Pyrotechnics Created in Particle Illusion</div>' + navImages};
function image9() {cycler()}; // Create infinite loop (without crashing browser).
function next() {nextClicked = 1};
function prev() {prevClicked = 1};
-->
</script>
And... Now it doesn't work. The first image shows up, and that's it. Back doesn't work, and next doesn't work. When I set a breakpoint and go line by line in Chrome, the text for the images shows up, as if everything is normal. But at runtime, it just gets stuck on the first image.
I'm new to JavaScript, suggestions are appreciated.