Solved

image timer

Posted on 2008-10-30
4
161 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:wilq32
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now