Hi guys.. :)
I'm still on my way on learning and seeing examples of JavaScript Codes
Today I saw this code (which depends on external file called *banner.js*)
<!-- Paste this code into an external JavaScript file named: banner.js.js -->
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Lee Underwood :: http://javascript.internet.com/ */
var bannerImg = new Array();
// Enter the names of the images below
bannerImg[0]="image_jss.gif";
bannerImg[1]="image_js.gif";
bannerImg[2]="image_wr.gif";
var newBanner = 0;
var totalBan = bannerImg.length;
function cycleBan() {
newBanner++;
if (newBanner == totalBan) {
newBanner = 0;
}
document.banner.src=bannerImg[newBanner];
// set the time below for length of image display
// i.e., "4*1000" is 4 seconds
setTimeout("cycleBan()", 4*1000);
}
window.onload=cycleBan;
<!-- Paste this code into the HEAD section of your HTML document.
You may need to change the path of the file. -->
<script type="text/javascript" src="banner.js.js"></script>
<!-- Paste this code into the BODY section of your HTML document -->
<img src="image_jss.gif" name="banner">
<p><div align="center">
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</div><p>
I've tried to make it work without using (external file), but it doesn't work!!! please anyone can tell me where's my mistake?
here's my code
<script type="text/javascript"> // adding the JavaScript prototype
var bannerRotate = new Array(); // creating new Array named "banner", and we set its value to unknown by saying * new Array() *
// Here you can create a list of whatever, images you want to add..
bannerRotate[0] = "image.gif";
bannerRotate[1] = "image2.gif";
bannerRotate[2] = "image3.gif";
var getNewBanner = 0;
var total = bannerRotate.length;
function rotate()
{
getNewBanner++;
// if statement to check the condition getNewBanner == to the total number of images, or not? if yes, then starts again from ZERO
if( getNewBanner == total )
{
getNewBanner = 0;
}
document.banner.src=bannerRotate[ getNewBanner ];
setTimeout = ( "rotate()", 4*1000 );
} // end function rotate
window.onload = rotate();
</script>
here's the code in <body>
<img src="image.gif" name="banner">
waiting for the help to keep learning from my mistakes :)
thanks in advance :)