I need a little help with my code there are 366 images to change called 001.jpg, 002.jpg … 366.jpg. It gets the date and put the picture for it. The code works but I can’t get it to output in my img tag.
<html>
<head>
<script type="text/javascript">
var firstJan = Math.floor((new Date().setFullYear(new Date().getFullYear(),0,1))/86400000);
var today = Math.ceil((new Date().getTime())/86400000);
var dayOfYear = today-firstJan;
var bgdImage;
if((dayOfYear+'').length == 1)
bgdImage = '00'+dayOfYear+'.jpg';
else if((dayOfYear+'').length == 2)
bgdImage = '0'+dayOfYear+'.jpg';
else
bgdImage = dayOfYear+'.jpg';
document.getElementById('bla').src = "bgdImage";
</script>
</head>
<body onload=img()>
<img id="bla" width="100%" height="100%" />
</body>
</html>
Like I said in the initial comment, put the code in the function
ìmg()you call in the<body onload="javascript:img();">. I also removed the quotes from your output statement to the src.document.getElementById('bla').src = bgdImage;bgdImageis your variable and putting it in quotes"bgdImage"is just a String with the text bgdImage inside.