...

View Full Version : Enlarging thumbnails stored in array



Zwake
09-14-2011, 08:04 PM
So when the page loads the thumbnails cycle through using setInterval. When the user clicks on one of the thumbnails, it is supposed to open a new window and show the enlarged version of that thumbnail stored in bigpics. However it only comes up with a broken image link. Any ideas why this is not working? Here is the code:

<html>
<head>
<title>Untitled</title>
</head>
<script language="JavaScript" type="text/javascript">
<!--
var pics = new Array()
pics[0]="pict1.gif"
pics[1]="pict2.gif"
pics[2]="pict3.gif"
pics[3]="pict4.gif"
pics[4]="pict5.gif"
pics[5]="pict6.gif"
var bigpics = new Array()
bigpics[0]="pict12.gif"
bigpics[1]="pict22.gif"
bigpics[2]="pict32.gif"
bigpics[3]="pict42.gif"
bigpics[4]="pict52.gif"
bigpics[5]="pict62.gif"
i=0
setInterval("slide()",500)
function slide(){
if (i<pics.length)
i++
if (i==pics.length)
i=0
document.images[0].src=pics[i]
}

function enlarge(x){
w=window.open()
x=bigpics[i]
w.document.write("<img src='x'>")
}
//-->
</script>
<body>
<img src="pict1.gif" alt="" onclick="enlarge(this)">
</body>
</html>

rnd me
09-14-2011, 08:12 PM
onclick="enlarge(this.src)">

Zwake
09-14-2011, 08:19 PM
Thats what i might have thought also, but when i try that it still comes up with a broken image link.

devnull69
09-14-2011, 09:34 PM
This


x=bigpics[i]
w.document.write("<img src='x'>")

will result in an image tag that is EXACTLY <img src='x'> but you want to concatenate the img tag string with the content of x


x=bigpics[i]
w.document.write('<img src="' + x + '">')

Zwake
09-14-2011, 10:37 PM
ahh yes that worked thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum