I have a javascript that places a random image from an array in the background of a div, but sometimes it doesn't work?
I just doesn't place anything in the html, but it does remove the 'default' background, which is done via the CSS.
here in the Jscript
// header 'calendar' image
var theImages=['morhead1', ' morhead2', 'morhead3', 'morhead4', 'morhead5', 'morhead6', 'morhead7', 'morhead8', 'morhead9', 'morhead10', 'morhead11', 'morhead12', 'morhead13', 'morhead14', 'morhead15'];
var p =14;
//var p = theImages.length;
var whichImage = Math.round(Math.random()*(p-1));
addEvent( window, 'load', function() {
document.getElementById('headimg').style.background="url(images/headpics_cal/"+theImages[whichImage]+".jpg) no-repeat"; } );
and this is the section of HTML it effects.
<div class="calhead" id="headimg">
<!--content of header -->
and this is usually the result
<div id="headimg" class="nocalhead" style="background: transparent url(images/headpics/morhead10.jpg) no-repeat"/>
however when it fails there ends up with no image in the background url string ie. url(images/headpics/).