...

View Full Version : Making script automatically start?



Cheeseboy
12-30-2006, 06:05 AM
Hi, i have this slideshow script but it will only start when i click on the "start" button i was wondering if anyone knew how to make it automatically start when the page loads:

<SCRIPT LANGUAGE="text/javascript">



NewImg = new Array (
"comp1.jpg",
"comp2.jpg",
"comp7.jpg",
"comp5.jpg",
"comp6.jpg",
"comp4.jpg"
);
var ImgNum = 0;
var ImgLength = NewImg.length - 1;


var delay = 4000;

var lock = false;
var run;
function chgImg(direction) {
if (document.images) {
ImgNum = ImgNum + direction;
if (ImgNum > ImgLength) {
ImgNum = 0;
}
if (ImgNum < 0) {
ImgNum = ImgLength;
}
document.slideshow.src = NewImg[ImgNum];
}
}
function auto() {
if (lock == true) {
lock = false;
window.clearInterval(run);
}
else if (lock == false) {
lock = true;
run = setInterval("chgImg(1)", delay);
}
}
javascript:auto()
</script>


The part in red i added but it did not work.
Here is the html code.

<img class="loader" src="comp1.jpg" name="slideshow">


Thanks!:thumbsup:

TripperTreats
12-30-2006, 06:09 AM
that's what the onload event is all about. is auto() the function that starts your slideshow? if so, just put this in your body tag:

<body onload="auto()">

Cheeseboy
12-30-2006, 06:32 AM
I placed the onload="auto()" in the body of my html document and the slide show did not start. I dont know if onload="auto()" is the right code to start the script.

Philip M
12-30-2006, 08:28 AM
I placed the onload="auto()" in the body of my html document and the slide show did not start. I dont know if onload="auto()" is the right code to start the script.

Show us exactly what you have, please.

Cheeseboy
12-30-2006, 08:32 PM
The javascript is above and the html is here:

<img class="space" src="righttable3.png" alt="image1" />
<img onload="auto()" class="loader" src="comp1.jpg" name="slideshow">


THanks!

vegu
12-30-2006, 08:50 PM
if you want it to start when the page loads you need to put it in the onload event of the body element


<body onload="auto()">

or


document.body.onload = auto;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum