View Full Version : Splitting up a random image/link/text script

06-19-2012, 01:05 PM
This is a very basic javascript queestion - so apologies in advance.

I currently have a perfectly working random image/link/text script. For the last day or so, I've been trying to split up the Arrays to generate linked results, but in different places.

By that, I mean I'd like to display the image/link arrays in one div, and the text array in a completely separate div. I assume I have to split up the document.write(...) part of the script, but I can't seem to do it without killing the entire operation. The script in questions is below:

<script language="JavaScript">

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish

//specify corresponding links below
var imagelinks=new Array()

var text = new Array()
text[1] ="share: 1"
text[2] ="share: 2"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
document.write('<a target="_blank" href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a><div class="linkbox">'+text[ry]+'</div>')

<div class="linkbox">-THIS IS WHERE I'D LIKE THE TEXT ARRAY TO APPEAR-</div>

Is what I'm asking even possible? Can you split up arrays and still produce linked results?

Thanks in advance!

06-19-2012, 03:35 PM
You Sir, are a gentleman and a scholar; it worked perfectly. Thank you for your help. I'll also make sure I use type="text/javascript" from now on!