Jump to content

Change Pictures


adrenalin

Recommended Posts

Hi.I am a newbie in javascript.I am trying to make something very simple:Display a picture on screen, and then from time to time change it to another.But the image never changes! Can someone please give me an hint of what may be wrong?Thanks.Here is my code:<html><head><script language="JavaScript">function timedCount(){ If (document["foto"].src=="pics/defeito1.JPG") { document["foto"].src="pics/defeito2.JPG"; } else { document["foto"].src="pics/defeito1.JPG"; }setTimeout("timedCount()",1000);}</script></head><body><IMG NAME="foto" SRC="pics/defeito1.JPG" height="180" width="230" ALT="Image"><body onload="timedCount()" ></body></html>

Link to comment
Share on other sites

You forgot to close the function. The script will not work properly if you do not close the function. It should be:function timedCount(){If (document["foto"].src=="pics/defeito1.JPG"){document["foto"].src="pics/defeito2.JPG";}else{document["foto"].src="pics/defeito1.JPG";}setTimeout("timedCount()",1000);}}</script>

Link to comment
Share on other sites

Hi.Thanks for your reply. But I dont think you are correct.Two "{" + "}" for the if/else block plus "{" + "}" for the function:<html><head><script language="JavaScript">function timedCount(){ If (document["foto"].src=="pics/defeito1.JPG") { document["foto"].src="pics/defeito2.JPG"; } else { document["foto"].src="pics/defeito1.JPG"; }setTimeout("timedCount()",1000);}</script></head><body><IMG NAME="foto" SRC="pics/defeito1.JPG" height="180" width="230" ALT="Image"><body onload="timedCount()" > ******HERE IT SEAMS THAT THE ERROR IS********</body></html>The infornation that I can read in internet explorer error description is:Line: 23Char: 1Error: Object expectedCode 0

Link to comment
Share on other sites

you have two open body tags <body> <body onload="timedCount()" > ******HERE IT SEAMS THAT THE ERROR IS********replace: <body>with:<body onload="timedCount()" > ******HERE IT SEAMS THAT THE ERROR IS********Theres more:'If' should be lowecase 'if' and finally:(document["foto"].src=="pics/defeito1.JPG")should include the full path ref for example:=="http://mydomain/pics/defeito1.JPG"OR you could use something likeif (document.images["foto"].src.indexOf("/pics/defeito1.JPG")!=-1)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...