...

View Full Version : Random image alt tag



murphyz
07-10-2002, 10:43 PM
Hey guys,

I have the following script in my page, and it works fine - giving me a random image when the page is refreshed. However, I was just wondering how you manage to put alt tags in so that when you hold the mouse over the picture it gives the comment box description?

<SCRIPT>
{img=new Array()
img[0]="../../../Images/XFiles/seasonone/pilotepisode/ash.JPG"
img[1]="../../../Images/XFiles/seasonone/pilotepisode/wrstwtch.JPG"
img[2]="../../../Images/XFiles/seasonone/pilotepisode/bmwtn.JPG"
img[3]="../../../Images/XFiles/seasonone/pilotepisode/marks.JPG"
img[4]="../../../Images/XFiles/seasonone/pilotepisode/corpse.JPG"
img[5]="../../../Images/XFiles/seasonone/pilotepisode/device.JPG"
img[6]="../../../Images/XFiles/seasonone/pilotepisode/devicere.JPG"
img[7]="../../../Images/XFiles/seasonone/pilotepisode/graves.JPG"
img[8]="../../../Images/XFiles/seasonone/pilotepisode/swenson.JPG"
img[9]="../../../Images/XFiles/seasonone/pilotepisode/nosebled.JPG"
img[10]="../../../Images/XFiles/seasonone/pilotepisode/exam.JPG"

mrnd = Math.floor(Math.random() * img.length)

document.writeln('<IMG SRC="'+img[mrnd]+'">')}
</SCRIPT>

thanks

Mxx

Vladdy
07-10-2002, 11:00 PM
document.writeln('<IMG SRC="'+img[mrnd]+'" ALT="'+img[mrnd]+'" >')}

;)

Cloudski
07-10-2002, 11:03 PM
Just make a second array...



alts=new array()
alts[0]="ash"
alts[1]="wrstwtch"
.....
alts[10]="exam"


and then for the document.write


document.writeln('<IMG SRC="'+img[mrnd]+'"alt="'+alts[mrnd]'">')


If unclear where to put everthing, tell me and I will post hte whle code :)

adios
07-10-2002, 11:07 PM
alts=new Array()

Cloudski
07-10-2002, 11:08 PM
Oooops..... :o

murphyz
07-10-2002, 11:10 PM
thanks very much guys...and, yes, I am unclear where to put the alts aspect of the code!

grrr.

Mxx

Cloudski
07-10-2002, 11:16 PM
Ok, here is the ENTIRE code....



<SCRIPT>
{img=new Array()
img[0]="../../../Images/XFiles/seasonone/pilotepisode/ash.JPG"
img[1]="../../../Images/XFiles/seasonone/pilotepisode/wrstwtch.JPG"
img[2]="../../../Images/XFiles/seasonone/pilotepisode/bmwtn.JPG"
img[3]="../../../Images/XFiles/seasonone/pilotepisode/marks.JPG"
img[4]="../../../Images/XFiles/seasonone/pilotepisode/corpse.JPG"
img[5]="../../../Images/XFiles/seasonone/pilotepisode/device.JPG"
img[6]="../../../Images/XFiles/seasonone/pilotepisode/devicere.JPG"
img[7]="../../../Images/XFiles/seasonone/pilotepisode/graves.JPG"
img[8]="../../../Images/XFiles/seasonone/pilotepisode/swenson.JPG"
img[9]="../../../Images/XFiles/seasonone/pilotepisode/nosebled.JPG"
img[10]="../../../Images/XFiles/seasonone/pilotepisode/exam.JPG"

alts=new Array()
alts[0]="whatever you want"
alts[1]="whatever you want"
alts[2]="whatever you want"
alts[3]="whatever you want"
alts[4]="whatever you want"
alts[5]="whatever you want"
alts[6]="whatever you want"
alts[7]="whatever you want"
alts[8]="whatever you want"
alts[9]="whatever you want"
alts[10]="whatever you want"


mrnd = Math.floor(Math.random() * img.length)


document.writeln('<IMG SRC="'+img[mrnd]+'"alt="'+alts[mrnd]'">')}

</SCRIPT>


There... I hope it helps :thumbsup:

murphyz
07-10-2002, 11:21 PM
Thanks cloudski - however, that doesn't seem to be working. No image is showing up at all.

And I've no idea why - could it be this part?

alt="'+alts[mrnd]

should [mrnd] be there?

Mxx

murphyz
07-10-2002, 11:23 PM
Panic over - it was missing a '+' symbol is all.

Thanks for all your help, now back to the grindstone!

Mxx

Cloudski
07-10-2002, 11:25 PM
And I've no idea why - could it be this part?

alt="'+alts[mrnd]


Oh Sorry... ir is supposed to be
document.writeln('<IMG SRC="'+img[mrnd]+'"alt="'+alts[mrnd]+'">')}

Thats what I get for not double checking my code...
:o

adios
07-10-2002, 11:28 PM
Unless you like typing...



<script type="text/javascript">

var imgPath = '../../../Images/XFiles/seasonone/pilotepisode/';
var img = new Array(
'ash.JPG' ,
'wrstwtch.JPG' ,
'bmwtn.JPG' ,
'marks.JPG' ,
'corpse.JPG' ,
'device.JPG' ,
'devicere.JPG' ,
'graves.JPG' ,
'swenson.JPG' ,
'nosebled.JPG' ,
'exam.JPG'
);

var alts = new Array(
'whatever you want' ,
'whatever you want' ,
'whatever you want' ,
'whatever you want' ,
'whatever you want' ,
'whatever you want' ,
'whatever you want' ,
'whatever you want' ,
'whatever you want' ,
'whatever you want' ,
'whatever you want'
);

var mrnd = Math.floor(Math.random() * img.length);
document.writeln('<img border="0" src="' + imgPath + img[mrnd] + '" alt="' + alts[mrnd] + '">');

</script>

Cloudski
07-10-2002, 11:41 PM
Ya.. I guess tha would work too :)

I was simply posting to the way he has it, since he already has the img Array built that way ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum