CSS/Scripting Help

Discussion in 'Web Design and Development' started by Aperture, Oct 22, 2006.

  1. Aperture macrumors 68000


    Mar 19, 2006
    Hi. I am working on coding my website in CSS. I found this code script online to randomly show an image out of a few. For example, if you put 5 images into the script, it will randomize the image that shows up per visit.
    This is the code:

    <script language="Javascript">
    // please keep these lines on when you copy the source
    // made by: Nicolas - http://www.javascript-page.com
    var currentdate = 0
    var core = 0
    function StringArray (n) {
      this.length = n;
      for (var i =1; i <= n; i++) {
        this[i] = ' '
    image = new StringArray(10)
    image[0] = '0.gif'
    image[1] = '1.gif'
    image[2] = '2.gif'
    image[3] = '3.gif'
    image[4] = '4.gif'
    image[5] = '5.gif'
    image[6] = '6.gif'
    image[7] = '7.gif'
    image[8] = '8.gif'
    image[9] = '9.gif'
    var ran = 60/image.length
    function ranimage() {
      currentdate = new Date()
      core = currentdate.getSeconds()
      core = Math.floor(core/ran)
    document.write("<img src='" +ranimage()+ "'>")
    If you look at this, I want to replace the picture of a bench with the random image. I suppose the best way to do this would be to take out the picture of the bench and leave that transparent, and embed the code beneath it.

    How can I do it so that I can tell the code where to put the image? I want it to fit just as the bench picture is, so it will look exactly like it is now. (except the image that shown, will be random)

    I don't want the Script to put the image way off to one side, obviously.

    I hope this isnt confusing.:(

    Any help appreciated!

  2. c-Row macrumors 65816


    Jan 10, 2006
    I can't test this right now, but I think it should work if you put the script in here...

    		<td colspan="9">
    			[B][SIZE="3"]<img src="images/Home_01.gif" width="952" height="391" alt="">[/SIZE][/B]</td>
    			<img src="images/spacer.gif" width="1" height="391" alt=""></td>
    ... replacing the bold line completely and slightly edit the script's last line to...

    document.write("<img src='" +ranimage()+ "' width='952' height='391'>")
    The slight edit is optional, but I guess you should try to keep it as close to the original code as possible. Not sure about the " and ' within JavaScript right now.

Share This Page