Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Making script automatically start?

    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:
    Code:
    <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.
    Code:
    <img class="loader" src="comp1.jpg" name="slideshow">

    Thanks!

  • #2
    New Coder TripperTreats's Avatar
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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()">
    Psychedelic digital art at www.trippertreats.com.

    "And in the end, the love you take
    is equal to the love you make
    ."

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by Cheeseboy View Post
    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.

  • #5
    Regular Coder
    Join Date
    Mar 2006
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The javascript is above and the html is here:
    Code:
    <img class="space" src="righttable3.png" alt="image1" />
    		<img  onload="auto()" class="loader" src="comp1.jpg" name="slideshow">
    THanks!

  • #6
    New Coder
    Join Date
    Dec 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you want it to start when the page loads you need to put it in the onload event of the body element

    Code:
    <body onload="auto()">
    or

    Code:
    document.body.onload = auto;
    http://demo.vegui.org - vegUI AJAX framework
    http://www.landsofkazram.com - browser based graphical MMORPG


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •