...

View Full Version : Code works in Chrome, but not IE :(



Safetybelt
06-21-2010, 12:18 AM
I'm just starting JavaScript and wrote a quick script for Next/Back buttons for a page showing a family outing on our boat. I proudly uploaded the webpage and emailed it out, but people running IE are unable to use the buttons, they simply do nothing.

Here is the .js file, I don't think anything in the HTML or CSS is causing the issue but could post those as well if necessary.



var step = 1;

//preload images
var numImages = 13;
var images = new Array( numImages );
var i = 0;
for ( i = 0; i < numImages; i++ )
{
images[i] = new Image();
images[i].src = "images/boat" + ( i + 1 ) + ".jpg";
}

function back()
{
if( step > 1 )
{
step--;
}
else
{
step = numImages;
}
document.images.slide.src = images[step-1].src;
}

function next()
{
if( step < numImages )
{
step++;
}
else
{
step = 1;
}
document.images.slide.src = images[step-1].src;
}

function init()
{
document.getElementById("back").onclick = back;
document.getElementById("next").onclick = next;
}

window.onload = init;


I've checked a lot of sites and can't figure this one out. :(

Also, if I'm practicing any bad coding techniques, I'm open to suggestions on that as well :)

randomuser773
06-21-2010, 02:12 AM
You have a conflict of ID and global objects with the same identifer "back", "next".

Rename the element IDs and the references to them.

Safetybelt
06-21-2010, 03:01 AM
Works now, thanks a ton!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum