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
Solved

image timer

Posted on 2008-10-30
4
163 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

860 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