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,

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.