?
Solved

rotating images with link

Posted on 2008-11-11
4
Medium Priority
?
870 Views
Last Modified: 2012-06-21
this is what i have so far. my images work fine but the link doesn't get change. could you help please.
if i take out document["ChangingLink"].href = Links[PicCurrentNum]; then my images loop through fine. but i also want my image to have link on them. the error i'm getting is document.ChangingLink is null or not an object. thank you
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
	var timeDelay = 5; 
	var Pix = new Array
	("images/1.jpg" 
	,"images/2.jpg" 
	,"images/3.jpg" 
	,"images/4.jpg" 
	);
	var Links = new Array
	("http://www.yahoo.com",
	 "http://www.google.com",
	 "http://www.etrade.com",
	 "http://www.microsoft.com"
	);
	var howMany = Pix.length;
	timeDelay *= 1000;
	var PicCurrentNum = 0;
	var PicCurrent = new Image();
	PicCurrent.src = Pix[PicCurrentNum];
	function startPix() {
	setInterval("slideshow()", timeDelay);
	}
	function slideshow() {
	PicCurrentNum++;
	if (PicCurrentNum == howMany) {
	PicCurrentNum = 0;
	LinkCurrentNum = 0;
	}
	PicCurrent.src = Pix[PicCurrentNum];
	document["ChangingLink"].href = Links[PicCurrentNum];
	document["ChangingPix"].src = PicCurrent.src;
	}
</script>
</head>
 
<body OnLoad="startPix()">
<a name="ChangingLink" id="ChangingLink" href="http://www.yahoo.com"><img name="ChangingPix" src="images/1.jpg" border="0"></a>
 
</body>
</html>

Open in new window

0
Comment
Question by:StewSupport
  • 3
4 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22933435
try:
document.images["ChangingLink"].href = Links[PicCurrentNum];
      document.images["ChangingPix"].src = PicCurrent.src;
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22933480
try:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
      var timeDelay = 5; 
      var Pix = new Array
      ("images/1.jpg" 
      ,"images/2.jpg" 
      ,"images/3.jpg" 
      ,"images/4.jpg" 
      );
	 
      var Links = new Array
      ("http://www.yahoo.com",
       "http://www.google.com",
       "http://www.etrade.com",
       "http://www.microsoft.com"
      );
	 
      var howMany = Pix.length;
      timeDelay *= 1000;
      var PicCurrentNum = 0;
      var PicCurrent = new Image();
      PicCurrent.src = Pix[PicCurrentNum];
	 
      function startPix() {
      setInterval("slideshow()", timeDelay);
      }
	 
      function slideshow() {
      	PicCurrentNum++;
      	if (PicCurrentNum == howMany) {
      		PicCurrentNum = 0;
      		LinkCurrentNum = 0;
      	}
      	PicCurrent.src = Pix[PicCurrentNum]; 
      	document.getElementById("ChangingLink").href = Links[PicCurrentNum];
      	document.getElementById("ChangingPix").src = PicCurrent.src;
      }
</script>
</head>
 
<body OnLoad="startPix()">
<a name="ChangingLink" id="ChangingLink" href="http://www.yahoo.com"><img name="ChangingPix" id="ChangingPix" src="images/1.jpg" border="0"></a>
 
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:StewSupport
ID: 31515664
thank you. just do documnet.getElementByID("").href
sob. don't know why it didn't work with just document.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22935720
you are welcome
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to implement server side field validation and display customized error messages to the client.
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

862 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