Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Web Design & Development Web Design & Development
Search Search
Search for:
Tech Support Guy > > >

Random Image Code Help


(!)

The Infinity's Avatar
The Infinity The Infinity is offline
Senior Member with 579 posts.
THREAD STARTER
 
Join Date: May 2005
Location: Florida
Experience: Advanced
01-Feb-2007, 09:06 PM #1
Question Random Image Code Help
I would like to use an random image code on my website like this one:

http://www.java-scripts.net/javascri...e-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.
namenotfound's Avatar
Member with 3,012 posts.
 
Join Date: Apr 2005
Location: New York
02-Feb-2007, 12:52 AM #2
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:


Quote:
<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's Avatar
The Infinity The Infinity is offline
Senior Member with 579 posts.
THREAD STARTER
 
Join Date: May 2005
Location: Florida
Experience: Advanced
02-Feb-2007, 04:01 PM #3
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's Avatar
The Infinity The Infinity is offline
Senior Member with 579 posts.
THREAD STARTER
 
Join Date: May 2005
Location: Florida
Experience: Advanced
03-Feb-2007, 06:26 PM #4
Well I tried looking up more scripts but none of them I could find would even work within DIV tags.
namenotfound's Avatar
Member with 3,012 posts.
 
Join Date: Apr 2005
Location: New York
03-Feb-2007, 06:35 PM #5
Couldn't you just do


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

and just wrap that javascript in div tags?
The Infinity's Avatar
The Infinity The Infinity is offline
Senior Member with 579 posts.
THREAD STARTER
 
Join Date: May 2005
Location: Florida
Experience: Advanced
03-Feb-2007, 07:55 PM #6
Quote:
Originally Posted by namenotfound
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.
namenotfound's Avatar
Member with 3,012 posts.
 
Join Date: Apr 2005
Location: New York
03-Feb-2007, 10:28 PM #7
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's Avatar
The Infinity The Infinity is offline
Senior Member with 579 posts.
THREAD STARTER
 
Join Date: May 2005
Location: Florida
Experience: Advanced
04-Feb-2007, 12:07 AM #8
Still doesn't work

It just won't display within the DIV tags.
knight_47's Avatar
knight_47 knight_47 is offline knight_47 has a Profile Picture
Senior Member with 941 posts.
 
Join Date: Mar 2006
Location: →
Experience: Um... Green?!
04-Feb-2007, 12:27 AM #9
Why don't you use a PHP script then? If you can, let me know.
The Infinity's Avatar
The Infinity The Infinity is offline
Senior Member with 579 posts.
THREAD STARTER
 
Join Date: May 2005
Location: Florida
Experience: Advanced
04-Feb-2007, 03:09 AM #10
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
namenotfound's Avatar
Member with 3,012 posts.
 
Join Date: Apr 2005
Location: New York
04-Feb-2007, 11:12 AM #11
Quote:
Originally Posted by The Infinity
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
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2