PDA

View Full Version : Array question...Help!



res11295
09-07-2005, 03:30 AM
I am currently modifying a DD script, Image Thumbnail Viewer II. But my question is a generic Javascript question.

How do I pass a value of an array to a funtion and then read it?

Exmaple:
var dynimages=new Array()
dynimages[0]=["wed01_medium.jpg", "wed01_large..jpg"]

I want to be able to store the image width and height. I'm not sure but think it should be like this:
dynimages[0]=["wed01_medium.jpg", "wed01_large.jpg",600,800]

Now I want to pass the values to the funtion below and replace the width and height values with the one in my array. I can't figure that out. Can someone help?

function returnimgcode(theimg){
var imghtml=""
if (theimg[1]!="")
imghtml='<a href="'+theimg[1]+'" onclick="window.open(this.href,\'popupwindow\',\'width=500,height=500,scrollbars=no,statusbar=no,resizable=yes,\');return false;" target="_blank">'
imghtml+='<img src="'+theimg[0]+'" border="'+imgborderwidth+'">'
if (theimg[1]!="")
imghtml+='</a>'
return imghtml
}


function modifyimage(loadarea, imgindex){
if (document.getElementById){
var imgobj=document.getElementById(loadarea)
if (imgobj.filters && window.createPopup){
imgobj.style.filter=filterstring
imgobj.filters[0].Apply()
}
imgobj.innerHTML=returnimgcode(dynimages[imgindex])
if (imgobj.filters && window.createPopup)
imgobj.filters[0].Play()
return false
}
}


THANK YOU!

jscheuer1
09-07-2005, 03:28 PM
imghtml='<a href="'+theimg[1]+'" onclick="window.open(this.href,\'popupwindow\',\'width='+theimg[2]+',height='+theimg[3]+',scrollbars=no,statusbar=no,resizable=yes,\');return false;" target="_blank">'

res11295
09-07-2005, 03:49 PM
Hi John,

Thanks for your help. I tried the code you provided but I'm getting an error 'theimage' is undefined. Any ideas?

Thanks,
Rick

jscheuer1
09-07-2005, 04:02 PM
Take another look at my code, I used:

theimg

not

theimage

res11295
09-07-2005, 04:04 PM
I'm sorry for the confusion, the error reads, theimg is undefined.

jscheuer1
09-07-2005, 04:14 PM
Tested here and works.
.

res11295
09-07-2005, 04:28 PM
Hi John,

I just copied and pasted the code again and it works like you said. Thanks for all your help!