SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rotating Images Code Help Please

    I am trying to rotate 5 images (each linking to a page on my website) but the code doesnt seem to work when I put in inside a table.
    Anyone have any idea where I am going wrong please?

    This is the code in <head> section


    <script language="JavaScript1.2">

    var howOften = 5; //number often in seconds to rotate
    var current = 0; //start the counter at 0
    var ns6 = document.getElementById&&!document.all; //detect netscape 6

    // place your images, text, etc in the array elements here
    var items = new Array();
    items[0]="<a href='commercial_cleaning.htm' ><img alt='image0 (9K)' src='rotate/image0.jpg' border='0' /></a>"; //a linked image
    items[1]="<a href='recycle_units.htm'><img alt='image1 (9K)' src='rotate/image1.jpg' border='0' /></a>"; //a linked image
    items[2]="<a href='pest_control.htm'><img alt='image2 (9K)' src='rotate/image2.jpg' border='0' /></a>"; //a linked image
    items[3]="<a href='washroom_services.htm'><img alt='image3 (9K)' src='rotate/image3.jpg' border='0' /></a>"; //a linked image
    items[4]="<a href='window_cleaning.htm'><img alt='image4 (9K)' src='rotate/image4.jpg' border='0' /></a>"; //a linked image
    function rotater() {
    document.getElementById("placeholder").innerHTML = items[current];
    current = (current==items.length-1) ? 0 : current + 1;
    setTimeout("rotater()",howOften*1000);
    }

    function rotater() {
    if(document.layers) {
    document.placeholderlayer.document.write(items[current]);
    document.placeholderlayer.document.close();
    }
    if(ns6)document.getElementById("placeholderdiv").innerHTML=items[current]
    if(document.all)
    placeholderdiv.innerHTML=items[current];

    current = (current==items.length-1) ? 0 : current + 1; //increment or reset
    setTimeout("rotater()",howOften*1000);
    }
    window.onload=rotater;
    //-->
    </script>

    and in body section (incide table) this code <layer id="placeholderlayer"></layer><div id="placeholderdiv"></div>


    Thanks in advance, any help greatly appreciated

  2. #2
    SitePoint Wizard Pedro Monteiro's Avatar
    Join Date
    Sep 2002
    Location
    Lisbon
    Posts
    1,393
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, would help if you could specify why its failing. Is it an error, or are the images simply not loading?=

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry - yes images are not loading at all , can be seen on this test page http://blitz-it.co.uk/test_page.htm

    thanks

  4. #4
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,727
    Mentioned
    44 Post(s)
    Tagged
    0 Thread(s)
    Your code is working, but I'm getting a 404 error on your images. I think you just need to check the addresses to your files.
    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  5. #5
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,727
    Mentioned
    44 Post(s)
    Tagged
    0 Thread(s)
    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are 2 functions there named 'rotator'.

    The second one is riddled with antiquated layers code and document.all code.
    Delete that entire function, plus the var = ns6 declaration near the top, plus the <layer> tag in the markup.
    Wipe them all totally, as they belong to the Netscape 4 / IE 4 era of the late 1990s.

    Now, the remaining problem in the surviving 'rotator' function will show up in your browser error console,
    but here it is too:

    <div id="placeholderdiv">

    function rotater() {
    document.getElementById("placeholder")

    This is all aside from any problems you may be having with image locations and loading,
    but try fixing the above and see where that takes you.

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry i am new at java, i have changed the code as follows and still not working

    <script language="JavaScript1.2">

    var howOften = 5;
    var current = 0;
    var ns6 = document.getElementById&&!document.all;
    var items = new Array();
    items[0]="<a href='/commercial_cleaning.htm' ><img src='0.jpg' border='0' /></a>"; //a linked image
    items[1]="<a href='/recycle_units.htm'><img src='1.jpg' border='0' /></a>"; //a linked image
    items[2]="<a href='/pest_control.htm'><img src='2.jpg' border='0' /></a>"; //a linked image
    items[3]="<a href='/washroom_services.htm'><img src='3.jpg' border='0' /></a>"; //a linked image
    items[4]="<a href='/window_cleaning.htm'><img src='4.jpg' border='0' /></a>"; //a linked image
    function rotater() {
    document.getElementById("placeholder").innerHTML = items[current];
    current = (current==items.length-1) ? 0 : current + 1;
    setTimeout("rotater()",howOften*1000);
    }

    function rotater() {
    if(document.layers) {
    document.placeholderlayer.document.write(items[current]);
    document.placeholderlayer.document.close();
    }
    if(ns6)document.getElementById("placeholderdiv").innerHTML=items[current]
    if(document.all)
    placeholderdiv.innerHTML=items[current];

    current = (current==items.length-1) ? 0 : current + 1;
    setTimeout("rotater()",howOften*1000);
    }
    window.onload=rotater;
    //-->
    </script>


    help please x

  8. #8
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for all your help, have now sorted the problem

  9. #9
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,727
    Mentioned
    44 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gooders2274 View Post
    thanks for all your help, have now sorted the problem
    Awesome, gled to hear that. What was it?
    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  10. #10
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    all i needed to do was put the full url of each image !


Bookmarks

Posting Permissions

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