Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Code works in Chrome, but not IE :(

    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.

    Code:
    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

  • #2
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    You have a conflict of ID and global objects with the same identifer "back", "next".

    Rename the element IDs and the references to them.

  • Users who have thanked randomuser773 for this post:

    Safetybelt (06-21-2010)

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Works now, thanks a ton!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •