jonathaw
06-22-2005, 11:53 PM
Yo, so I have 20 images, named 1.jpg, 2.jpg, etc. I want a random one to load each time the page is viewed, so I have Frankensteined the following code together:
****************************************
<script language="JavaScript">
var length = 20;
var ran_num = Math.round((length-1)*Math.random());
document.write("<img src='splash_pics/"+ran_num+".jpg'>");
document.splash.src = "splash_pics/"+ran_num+".jpg";
</script>
<img id="splash" src="../splash_pics/19.jpg" />
****************************************
The document.write part works just fine, but I need to make sure an image is displayed even if javascript is disabled. So, the second part (document.splash.src...) is what I need to work, because it should override src="../splash_pics/19.jpg" right???
I always get an error that says "document.splash has no properties" and I'm not familiar enough with javascript to know how to fix this. Why this no worky?
BTW, I know this would take about 2 lines of PHP, but... well I'm using javascript.
****************************************
<script language="JavaScript">
var length = 20;
var ran_num = Math.round((length-1)*Math.random());
document.write("<img src='splash_pics/"+ran_num+".jpg'>");
document.splash.src = "splash_pics/"+ran_num+".jpg";
</script>
<img id="splash" src="../splash_pics/19.jpg" />
****************************************
The document.write part works just fine, but I need to make sure an image is displayed even if javascript is disabled. So, the second part (document.splash.src...) is what I need to work, because it should override src="../splash_pics/19.jpg" right???
I always get an error that says "document.splash has no properties" and I'm not familiar enough with javascript to know how to fix this. Why this no worky?
BTW, I know this would take about 2 lines of PHP, but... well I'm using javascript.