Solved

image timer

Posted on 2008-10-30
4
162 Views
Last Modified: 2013-11-05
I can not get this code to work, what am I doing wrong.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang = "en" 
 
dir="ltr">
 
<head>
 
<meta http-equiv="content-type" content="text/html; charset=iso-8859-
 
1" />
 
<title>ConcertAd</title>
<script type="text/javascript">
/*<![CDATA[ */
 
if (curImage == "concert2")
{
document.images[1].src = "concert1.gif";
	curImage = "concert1";
}
else 
}
 
document.images[2].src = "concert2.gif";
curImage="concert2";
}
 
/*]]>*/
</script>
 
</head>
 
<body onload ="var begin=setInterval ('changeImages( )', 5000);">
<p><img src="concert1.gif"  alt=""/></p>
</body>
</html>

Open in new window

0
Comment
Question by:munzie
4 Comments
 
LVL 16

Accepted Solution

by:
Lolly-Ink earned 50 total points
ID: 22847261
Here's a cleaner version of your code with fixes applied:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang = "en" dir="ltr">
<head>
   <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
   <title>ConcertAd</title>
   <script type="text/javascript">
      var curImage = "concert1";
 
      function changeImages()
      {
         if (curImage == "concert2")
         {
            document.images[0].src = "concert1.gif";
            curImage = "concert1";
         }
         else 
         {
            document.images[0].src = "concert2.gif";
            curImage="concert2";
         }
      }
   </script>
</head>
<body onload="setInterval('changeImages()', 5000)">
   <p><img src="concert1.gif"/></p>
</body>
</html>

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 22847303
>>what am I doing wrong.
You are "opening" your else with "}":
else
}


 It should be "{"
else
{
0
 
LVL 18

Expert Comment

by:Pawel Witkowski
ID: 22849650
yes and you forgot to define:

var curImage="concert1";

0
 

Author Comment

by:munzie
ID: 22853452
Thanks, I see what was wrong.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question