I have an application where I am trying to run a slide show. I am not very familiar with JavaScript but have made an attempt to put together some script. As expected, it does not work well ! When I launch the page, no initial immage is being shown and, of course, images do no rotate (not a big surprise to me). I've been working on this for a couple of days and I am STUCK Here is the code snippet I have. Appreciate any comments and ideas. Note: If I enter the JavaScript portion into a notepad and run as html it works fine (but not in asp) <%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %> <!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 id="Head1" runat="server"> <title>Test - JavaScript Slide Show</title> <script type="text/javascript"> var image1=new Image() image1.src="/Images/01.jpg" var image2=new Image() image2.src="/Images/02.jpg" var image3=new Image() image3.src="/Images/04.jpg" </script> </head> <body onload="slideit()"> <img onload="slideit()" alt="No Image" src="/images/01.jpg" name="slide" width="100" height="50" /> <script type="text/javascript"> var step=1 function slideit() { if (!document.images) return document.images.slide.src=eval("image"+step+".src") if (step<3) step++ else step=1 setTimeout("slideit()",2500) } </script> <form id="form1" runat="server"> <div> <table border="1" style="left: 2px; width: 1088px; position: relative; top: -26px; height: 1px; border-right-style: none; border-bottom-style: none;"> <tr>.......... PHP:
Figured it out. This code will work... <!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 id="Head1" runat="server"> <title>Test - JavaScript Slide Show</title> <script type="text/javascript"> var image1=new Image() image1.src="Images/01.jpg" var image2=new Image() image2.src="Images/02.jpg" var image3=new Image() image3.src="Images/04.jpg" </script> </head> <body onload="slideit()"> <img alt="No Image" src="images/01.jpg" name="slide" width="100" height="50" /> <script type="text/javascript"> var step=1 function slideit() { if (!document.images) return document.images.slide.src=eval("image"+step+".src") if (step<3) step++ else step=1 setTimeout("slideit()",2500) } </script> <form id="form1" runat="server"> <div> <table border="1" style="left: 2px; width: 1088px; position: relative; top: -26px; height: 1px; border-right-style: none; border-bottom-style: none;"> <tr>....... PHP:
each line in javascript should end with ; First section; var image1=new Image(); image1.src="/Images/01.jpg"; var image2=new Image(); image2.src="/Images/02.jpg"; var image3=new Image(); image3.src="/Images/04.jpg"; Code (markup): Second section: var step=1; function slideit() { if (!document.images) return; document.images.slide.src=eval("image"+step+".src"); if (step<3) step++; else step=1; window.setTimeout("slideit()",2500); } Code (markup): Also you don't need the onload="slideit();" within the <img tag, just the <body