Click to See Complete Forum and Search --> : Random Image Array
ottz0
07-22-2004, 02:02 AM
I have downloaded a random image script that uses arrays ,but it wont display the images.
It also uses hyperlinks to differerent urls and when refreshed the links also change. This part works so i know the script is calling in the array. I have also renamed my images that are consistent to the varables used.
eg: img1,img2,img3 etc. So everything looks correct.
So why no images are displaying? Just get the blank box in the browswer and the reference looks ok when checking the properties in the browser also.
thanks
neil9999
07-22-2004, 02:04 AM
Post your code please...
Neil
ottz0
07-22-2004, 02:10 AM
<--//
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"
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>')
}
random_imglink()
//-->
JacksonCochrane
07-22-2004, 07:45 AM
Try it this way:
<HTML>
<Head>
<Script Language=JavaScript>
var ry = 0;
var myimages=new Array();
var imagelinks=new Array();
function random_imglink(){
myimages[1]="img1.gif"
myimages[2]="img2.gif"
myimages[3]="img3.gif"
imagelinks[1]="http://www.wsabstract.com"
imagelinks[2]="http://www.dynamicdrive.com"
imagelinks[3]="http://www.java-scripts.net"
ry=Math.floor(Math.random()*myimages.length)
if (ry==0){ry=1}
}
random_imglink()
</Script>
</Head>
<Body>
<Div id=randomIMGlink>
</Div>
<Script> // you must keep this script below the DIV
buildStr = "<a href="+imagelinks[ry]+"><img src="+myimages[ry]+"></a>"
randomIMGlink.innerHTML = buildStr;
</Script>
</Body>
</HTML>
ottz0
07-22-2004, 01:50 PM
sorry. Still the same. I've tried a few scripts and still can't get the images to display. The links work but still the images have the blank box. The images are displayed accordinly.
the only way I can seen an image is if i start the images at 0. I think slideshows work that way. But if I start it at 0.gif it will only display the random image of 0.gif and not anything else
thanks
JacksonCochrane
07-22-2004, 05:22 PM
,
JacksonCochrane
07-22-2004, 05:28 PM
Okay, then try this:
<HTML>
<Head>
<Script Language=JavaScript>
var myimages=new Array();
myimages[0]="img1.jpg"
myimages[1]="img2.jpg"
myimages[2]="img3.jpg"
var imagelinks=new Array();
imagelinks[0]="1.html"
imagelinks[1]="2.html"
imagelinks[2]="3.html"
var isLink = 0;
var initStr = "<a href="+imagelinks[2]+"><img src="+myimages[2]+"></a>"
function setLink(curr){
buildStr = "<a href="+imagelinks[curr]+"><img src="+myimages[curr]+"></a>";
randomIMGlink.innerHTML = buildStr;
}
function randomize(){
isLink = Math.random();
isLink= isLink.toFixed(1);
isLink = isLink*10;
if (isLink <= 2){setLink(isLink)}
}
function getRandomLink(){
randomize();
if (isLink > 2){setTimeout("getRandomLink()",1)}
else {randomIMGlink.style.visibility = "visible"}
}
</Script>
</Head>
<Body>
<Div id=randomIMGlink></Div>
<Script>
randomIMGlink.style.visibility = "hidden"
randomIMGlink.innerHTML = initStr;
getRandomLink();
</Script>
</Body>
</HTML>
ottz0
07-23-2004, 01:28 AM
Hi, Thanks for your reply.
The images still won't display. I have named them exactly the same as in the script and the html file resides in the same folder.
The script works and links and runs the images when i check them in the browser, just the images won't display.
Is it a browser setting? or someting i'm not doing right?
thanks
ottz0
07-23-2004, 02:03 AM
Everythig display ok. Dreamweaver had referenced my temp files wrong. To me Javascript should stil display but I tryed moving the files into IIS instead of a virtual directory and it works. Don't know why this should have been a problem, but thanks
ottz