adrenalin Posted July 25, 2009 Report Share Posted July 25, 2009 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 More sharing options...
webmaster Posted July 26, 2009 Report Share Posted July 26, 2009 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 More sharing options...
adrenalin Posted July 26, 2009 Author Report Share Posted July 26, 2009 (edited) 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 Edited July 26, 2009 by adrenalin Link to comment Share on other sites More sharing options...
dsonesuk Posted July 26, 2009 Report Share Posted July 26, 2009 (edited) 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) Edited July 26, 2009 by dsonesuk Link to comment Share on other sites More sharing options...
adrenalin Posted July 26, 2009 Author Report Share Posted July 26, 2009 Yes!That was it! Thanks a lot.:-)) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now