0

Hi all,
I'm trying to develop a javascript to display a few images in a div. The plan is to get two pictures which will act as next/last image, but I'm stuck for running the script when the page loads, which is using the onLoad function in the body tag.

function slideshow(src)
{
	var picture=new Array();
	picture[0]="package1.jpg";
	picture[1]="package2.jpg";
	var active=0;
	document.getElementById('packages').innerHTML="<img src=\"+ picture[0] +\">";
}

So now, the code finds the div, but it has a problem accessing the location of the Array. I've hardcoded it in, when I attempted to see if it was the structure of the code. How do I fix it? Looks like it's ignoring the + signs, which I thought were to add variables.

Cheers,

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by fxm
0

This

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <meta name="generator" content=
    "HTML Tidy for Windows (vers 25 March 2009), see www.w3.org">
    <title></title>
  </head>
  <body onload="slideshow()">
    <div id='packages'></div>
  <script type="text/javascript">
	function slideshow(src){
        var picture=new Array();
        picture[0]="package1.jpg";
        picture[1]="package2.jpg";
        var active=0;
        document.getElementById('packages').innerHTML="<img src="+ picture[0] +">";
	}
    </script>
  </body>
</html>

fixes the immediate problem.

However, it is not obvious why you are writing .innerHTML instead of just setting the .src property of an <img> tag.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.