Random Image Code Help

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

The Infinity

Thread Starter
Joined
May 11, 2005
Messages
579
I would like to use an random image code on my website like this one:

http://www.java-scripts.net/javascripts/Random-Image-Script.phtml

The only problem is I want a caption to be under the image such as "Turtleman's Image" and when it changes to another image have it display different text for the other image such as "Turtleman's Brother's Image".

Sorry for the weird example but I think that gets the point across.
 
Joined
Apr 30, 2005
Messages
3,012
Ok I know very little JavaScript, but just looking at the code, I'm going to take an educated guess. This may or may not work. My edits will be in bold:


<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"


//Caption, this may or may not work.
var caption=new Array()
var caption[1]="Turtleman's Image"
var caption[2]="Turtleman's Brother's Image"
var caption[3]="namenotfound is trying his best"


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>')
document.write('+caption[ry]+')
}

random_imglink()
//-->
</script>
 

The Infinity

Thread Starter
Joined
May 11, 2005
Messages
579
The only thing is I need a code that will work within DIV tags.

And so far I can't get the code above to work :(
 

The Infinity

Thread Starter
Joined
May 11, 2005
Messages
579
Well I tried looking up more scripts but none of them I could find would even work within DIV tags.
 
Joined
Apr 30, 2005
Messages
3,012
Couldn't you just do


<div>
<script>
...
</script>
</div>

and just wrap that javascript in div tags?
 

The Infinity

Thread Starter
Joined
May 11, 2005
Messages
579
namenotfound said:
Couldn't you just do


<div>
<script>
...
</script>
</div>

and just wrap that javascript in div tags?
technically yes but according to W3C validation its not valid.
 
Joined
Apr 30, 2005
Messages
3,012
Change <script language="JavaScript"> to <script type="text/javascript"> that should then validate.

<div>
<script type="text/javascript">
......
</script>
</div>

It validated when I tried.
 

The Infinity

Thread Starter
Joined
May 11, 2005
Messages
579
Actually I got it. I ended up having to tweak the script a lot to get it to recognize everything but it worked.

And the script tags did finally end up working inside the div tags :)
 
Joined
Apr 30, 2005
Messages
3,012
The Infinity said:
Actually I got it. I ended up having to tweak the script a lot to get it to recognize everything but it worked.

And the script tags did finally end up working inside the div tags :)
Glad you got it working :)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top