If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member Zdroyd's Avatar
    Join Date
    Nov 2010
    Member #
    Hello, for my site I have a graphic that I want to randomly change between different graphics of the same size. Here is my site: the image that is under the header is the background of a table. I have the following code:

    <script language="javascript">
    onload = function() {
    /* If you change the directory, make sure you update it here. */
    var imageDirectory = "";
    /* If you want to add more images on your own, put the the file name in the middle
    of the list here.  Make sure there are quotes around it and a comma at the end. */
    var imageArray = new Array("image3.gif",
    var imageArrayLength = imageArray.length; // Leave these next few lines alone
    var pseudoRandomNumber = ( Math.round( Math.random() * (imageArrayLength - 1) ) );
    document.getElementById("tableImage").style.backgroundImage="url('" +
    "imageDirectory + imageArray[pseudoRandomNumber] + "')";
    <style type="text/css">
    #tableImage {
    <table id="tableImage" height="431" width="465">
    <tr><td> </td></tr>
    This changes the tables background at random when the page loads, but I want it to also randomly change after a set time of seconds.

    Could someone help me with editing the code to do this?



  3. #2
    Senior Member paintingtheweb's Avatar
    Join Date
    Jul 2007
    Las Vegas
    Member #
    wrap your code in setInterval().

    //put your code in here
    }), 3000); //the 3000 number is the time in milliseconds. In this case it would be 3 seconds.

Remove Ads

Posting Permissions

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

Search tags for this page

java script code for random background images in the table

Click on a term to search for related topics.
All times are GMT -6. The time now is 02:54 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: