Any JavaScript nuts out there??

Discussion in 'OT Technology' started by ijustwantpics, Oct 19, 2005.

  1. ijustwantpics

    ijustwantpics New Member

    Joined:
    Dec 23, 2003
    Messages:
    571
    Likes Received:
    0
    Location:
    Minneapolis
    I need a bit of help with a "New image on load" Script. I've found a few on the net but haven't been able to get them to work for me. Also I'd like these images to be linked as well.


    Here's what I'm working with now

    <script language="JavaScript">
    <!--
    function random_imglink(){
    var myimages=new Array()
    //specify random images below. You can have as many as you wish
    myimages[1]="<img src='images/enter2.jpg' border='0'>"
    myimages[2]="<img src='images/enter3.jpg' border='0'>"
    myimages[3]="<img src='images/enter4.jpg' border='0'>"

    //specify corresponding links below
    var imagelinks=new Array()
    imagelinks[1]="main.html"
    imagelinks[2]="main.html"
    imagelinks[3]="main.html"

    var ry=Math.floor(Math.random()*myimages.length)
    if (ry==0)
    ry=1
    document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
    }
    random_imglink()
    //-->
    </script>



    I place this between my body tags and the only thing that happens is I loose anything in my <body> tag. Thoughts?
     
  2. Keyzs

    Keyzs OT Supporter

    Joined:
    Nov 3, 2003
    Messages:
    814
    Likes Received:
    0
    Location:
    Charlotte, MI
    The original script that you used:

    Code:
    <script language="JavaScript">
    <!--
    /*
    Random Image Link Script
    By Website Abstraction (http://www.wsabstract.com)
    and Java-scripts.net (http://www.java-scripts.net)
    */
    
    function random_imglink(){
      var myimages=new Array()
      //specify random images below. You can have as many as you wish
      myimages[1]="img1.gif"
      myimages[2]="img2.gif"
      myimages[3]="img3.gif"
    
      //specify corresponding links below
      var imagelinks=new Array()
      imagelinks[1]="http://www.wsabstract.com"
      imagelinks[2]="http://www.dynamicdrive.com"
      imagelinks[3]="http://www.java-scripts.net"
    
      var ry=Math.floor(Math.random()*myimages.length)
    
      if (ry==0)
         ry=1
         document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
    }
    
      random_imglink()
    //-->
    </script>
    
    
    Note the images are just the file name without the "<img src" and "border='0' "etc. Its redundant.

    Try:
    Code:
    <script language="JavaScript">
    <!--
    function random_imglink(){
    var myimages=new Array()
    //specify random images below. You can have as many as you wish
    myimages[1]="images/enter2.jpg"
    myimages[2]="images/enter3.jpg"
    myimages[3]="images/enter4.jpg"
    
    //specify corresponding links below
    var imagelinks=new Array()
    imagelinks[1]="main.html"
    imagelinks[2]="main.html"
    imagelinks[3]="main.html"
    
    var ry=Math.floor(Math.random()*myimages.length)
    if (ry==0)
    ry=1
    document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
    }
    random_imglink()
    //-->
    </script>
    
     
  3. ijustwantpics

    ijustwantpics New Member

    Joined:
    Dec 23, 2003
    Messages:
    571
    Likes Received:
    0
    Location:
    Minneapolis
    Thanks for the help, it seems to be working. One additional question, is there any way to center the images?


    Edit: After looking at it a little bit more it's only working for me if I have the code in both the head and body tags. Do I need to link the images within the body tags? Is so how?
     
    Last edited: Oct 19, 2005
  4. Keyzs

    Keyzs OT Supporter

    Joined:
    Nov 3, 2003
    Messages:
    814
    Likes Received:
    0
    Location:
    Charlotte, MI
    You should only need it where you want the images to be located.

    Using your code...
    Code:
    <HTML>
    <HEAD>
        <TITLE>Kurupt Visionz!</TITLE>
    <META NAME ="keywords" CONTENT="Minnesota, Truck, Club, Kurupt Visionz, Visions, bags, drop, dropped, air ride, car, truck, s10, ranger, lowered, pics, pictures, lift, lifted, kits, parts, billet, grills, grilles, grill, grille, hood, hoods, wheels, tires, jeep, custom, 4 link, air line, tanks, fittings, viair, Suicide Doors, Goodmark, Daystar, Kurupt Kustoms, kuruptkustoms.com">
    <META NAME="description" CONTENT="Kurupt Visionz - Representing Minnesota to the fullest!">
    <!--// Kurupt Visionz - Representing Minnesota to the fullest! //--!>
    </HEAD>
      <BODY bgcolor="#000000" link="#FFFF00" vlink="#FFFF00">
    <center>
    <script language="JavaScript">
    <!--
    function random_imglink(){
    var myimages=new Array()
    //specify random images below. You can have as many as you wish
    myimages[1]="images/enter2.jpg"
    myimages[2]="images/enter3.jpg"
    myimages[3]="images/enter4.jpg"
    
    //specify corresponding links below
    var imagelinks=new Array()
    imagelinks[1]="main.html"
    imagelinks[2]="main.html"
    imagelinks[3]="main.html"
    
    var ry=Math.floor(Math.random()*myimages.length)
    if (ry==0)
    ry=1
    document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
    }
    random_imglink()
    //-->
    </script>
    <BR>
    <BR>
    <BR>
    <br>
    <font size=+2><a href="main.html" style="color=red">CLICK TO ENTER Kurupt Visionz!</a></center></font>
    <br>
    <br>
    <br>
    <center><font color=white size=-1>Best viewed @ 1280x1024<br><A HREF="mailto:[email protected]" style="text-decoration:none" style="color=red">
    Webmaster</A>
    
    </center>
      </BODY>
    </HTML>
    
     
  5. ijustwantpics

    ijustwantpics New Member

    Joined:
    Dec 23, 2003
    Messages:
    571
    Likes Received:
    0
    Location:
    Minneapolis
    Man I really don't know what I'm doing wrong.. I tried out the code you provided and it basically F'd the whole page. The image didn't appear, text was shifted left and I had no <body> settings again.

    I went ahead and entered the code in both the body and the head again and it seems to be working that way for some odd reason. I don't even know what to do.

    Thanks for all your help so far Keyzs
     
    Last edited: Oct 19, 2005
  6. Keyzs

    Keyzs OT Supporter

    Joined:
    Nov 3, 2003
    Messages:
    814
    Likes Received:
    0
    Location:
    Charlotte, MI
    check your email...
     

Share This Page