Images Continuous Slideshow [Resolved]

Posted by Nkkppp under ASP.NET on 8/24/2012 | Points: 10 | Views : 2030 | Status : [Member] | Replies : 1
Below is the Javascript code for the slideshow. I have a small query may be even silly. In the below JS code when i initially tries the window.setTimeout("Images(imgnumber)",3000) it was not working after a lot of google search i found the way to pass parameter.Can you please let me know why it didn't work with window.setTimeout("Images(imgnumber)",3000)

<script type="text/javascript">
var myarr = new Array("Images/Sunset.jpg", "Images/Winter.jpg", "Images/Blue hills.jpg", "Images/Water lilies.jpg");
function Images(imgnumber) {
document.getElementById("<%=img.ClientID%>").src = myarr[imgnumber];
imgnumber += 1;
if (imgnumber == myarr.length)
imgnumber = 0;
if (imgnumber < myarr.length)
window.setTimeout("Images(" + imgnumber + ")", 3000);}
<body onload="Images(0)">
<form id="form1" runat="server">
<asp:ImageButton ID="img" runat="server" CssClass="img" />


Posted by: Deepraj on: 8/27/2012 [Member] Starter | Points: 50


Hi Nkppp,
The problem with the window.setTimeout("Images(imgnumber)",3000) is you are not actually passing value,instead you are passing string "imgnumber" thats why it doesn't work.
To get value of any variable it should not be in double quotes
var a=10;

Here simply
alert(a);// gives 10 as output;
alert("a");//gives nothing as you are passing string

Nkkppp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response