Forum Moderators: open
<!--<HTML>
<HEAD>
<META NAME="Generator" CONTENT="Stone's WebWriter 3.5">
<TITLE>imagesByButtos</TITLE>
<SCRIPT TYPE="text/javascript">
var pr1= new Image();
pr1.scr="images1.jpeg"
var pr2= new Image();
pr2.scr="images2.jpeg"
var pr3= new Image();
pr3.scr="images3.jpeg"
var pr4= new Image();
pr4.scr="images4.jpeg"
var pr5= new Image();
pr5.scr="images5.jpeg"
var pr6= new Image();
pr6.scr="images6.jpeg"
var people=new Array( pr1.scr, pr2.scr, pr3.scr, pr4.scr, pr5.scr, pr6.scr);
function change()
{
document.images['chpeople'].src =people[1];
}
document.images['chpeople'].src =people[3];
</SCRIPT>
</HEAD>
<BODY onload="change()">
<IMG NAME = "chpeople" SRC="images1.jpeg" BORDER="0" ALIGN="bottom" ALT="changing people"><BR>
<form>
<INPUT TYPE="button" VALUE="image1" name="ch1" onclick="document.images['chpeople'].src =people[0]">
<INPUT TYPE="button" VALUE="image2" name="ch2" onclick="document.images['chpeople'].src =people[1]">
<INPUT TYPE="button" VALUE="image3" name="ch3" onclick="document.images['chpeople'].src =people[2]">
<INPUT TYPE="button" VALUE="image4" name="ch4" onclick="document.images['chpeople'].src =people[3]">
<INPUT TYPE="button" VALUE="image5" name="ch5" onclick="document.images['chpeople'].src =people[4]">
<INPUT TYPE="button" VALUE="image6" name="ch6" onclick="document.images['chpeople'].src =people[5]">
</form>
</BODY>
</HTML>-->
document.images['chpeople'].src =people[3]; This line is not inside a function, and thus executed immediately (as soon as it is read). At that time, the image element( document.images['chpeople'] ) doesn't yet exist, since the HTML for it has not been parsed.
This is why the onload event is so often used for things like this.
(note: The collection, document.images does itself exist at the time, but is empty)
var pr1= new Image();
Creates an image object.
pr1.scr="images1.jpeg"
Assigns the image as the source file of the object. Usually.
What is scr? If you mean that to preload an image, it should be pr1.src.