?
Solved

image timer

Posted on 2008-10-30
4
Medium Priority
?
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 16

Accepted Solution

by:
Lolly-Ink earned 200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

752 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