I have the following code, where i try to preload the images. It is not working it just shows broken images.
If I remove the
[code]
img[x]=new Image;
it works fine, when I is when i try to preload them that it fails to show the images..
can you see what i am doing wrong?
[code]
<html>
<head>
<title>week 10 ex 5</title>
<script type=”text/javascript” language=”javascript”>
function writeDate(y){
// Set up our variables
var img = new Array(“”);
var today = new Date();
var date = String(today.getDate());
var month = String(today.getMonth()+1);
var year = String(today.getFullYear());
var date1 = date.charAt(0);
var date2 = date.charAt(1);
// Prime the img array
for (x = 1; x <= 7; x++) {
img[x] = document.getElementById(“img”+String(x));
}
// Set src of appropriate images an preload the images
// 1&2 = day, 3 = month, 4-7 = year
if (date2 == “”) {
img[2]=new Image;
img[2].src = date1 + “.gif”;
img[1]=new Image;
img[1].src = “space.gif”;
}
else {
img[1]=new Image;
img[1].src = date1 + “.gif”;
img[2]=new Image;
img[2].src = date2 + “.gif”;
}
img[3]=new Image;
img[3].src = “month” +month+ “.gif”;
img[4]=new Image;
img[4].src = year.charAt(0) + “.gif”;
img[5]=new Image;
img[5].src = year.charAt(1) + “.gif”;
img[6]=new Image;
img[6].src = year.charAt(2) + “.gif”;
img[7]=new Image;
img[7].src = year.charAt(3) + “.gif”;
if(y == ‘eu’){
img[1].src=”./images/dateimgs/month” + month + “.gif”;
if (date2 == “”) {
img[1].scr =”month” +month+ “.gif”;
img[3].src = date1 + “.gif”+”.”;
img[2].src = “space.gif”;
} else {
img[1].src =”month” +month+ “.gif”;
img[3].src = date1 + “.gif”+”.”;;
img[2].src = date2 + “.gif”+”.”;
}
}
}
</script>
</head>
<body bgcolor=”#faf0e6″>
<HR WIDTH=”80%”>
<CENTER>
<FONT color=”green”>
<H1>Week 10 Exercise 4</H1>
<H3>Taylor Waldron</H3></font>
<HR WIDTH=”80%”>
<A HREF=”index.html”><H4>Taylor Waldron’s Homepage</H4></A> <A HREF=”homework.html”><H4>HOMEWORK</H4></A>
<br/>
<br/>
<table id=”dateTable” border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td><img id=”img1″ name=”img1″ border=”0″ /></td>
<td><img id=”img2″ name=”img2″ border=”0″ /></td>
<td><img id=”img3″ name=”img3″ border=”0″ /></td>
<td><img id=”img4″ name=”img4″ border=”0″ /></td>
<td><img id=”img5″ name=”img5″ border=”0″ /></td>
<td><img id=”img6″ name=”img6″ border=”0″ /></td>
<td><img id=”img7″ name=”img7″ border=”0″ /></td>
</tr>
</table>
<script type=”text/JavaScript”>
writeDate(‘us’);
</script>
<input type=”button” value=”English” onclick=”writeDate(‘us’)”/>
<input type=”button” value=”Europe” onclick=”writeDate(‘eu’)”/>
</center>
</body>
</html>