How to make a function run when web page loads.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TonyJeffs

    #1

    How to make a function run when web page loads.

    I'm new to this, and stole/doctored my code from the "Ugly JavaScript
    Handbook"

    I have a slide show program.
    First theres stuff to set up the array, and the time between slides
    Then a function startIt()is defined
    then a function stopIt()
    Then two buttons, Start and Stop, which when pressed call the relevant
    functions

    When the page loads, you have to click the Start button to get the
    slide show running, but I'd like it to start running straight away
    without having to click.
    I can't for the life of me figure this out.
    I thought it was just a question of putting the line
    startIt();
    in the appropriate place.

    Here's the whole of the code

    Thanks

    Tony

    <HTML><HEAD>
    <TITLE>Holida y</TITLE>

    <SCRIPT LANGUAGE="JavaS cript">
    <!-- Hide from JavaScript-Impaired Browsers
    var ctr=1;
    var pics=17;
    var speed=3500; // set initial
    var ns="0123456789" ; // number index
    /* First, create a new array and then
    create an image holder and load it
    with the logo animation images. */
    isn=new Array();
    startIt()
    for (i=1;i<=pics;i+ +){
    isn[i]=new Image();
    isn[i].src=i+".jpg";
    }
    startIt()
    /* Next do the same for the number
    images to display speed. */
    nr=new Array();
    for (i=0;i<=pics;i+ +){
    nr[i]=new Image();
    nr[i].src="nr/"+i+".jpg";

    startIt()
    }

    function startIt(){
    document.ugly.s rc=isn[ctr].src;
    ctr=(ctr>(pics-2)?1:++ctr);
    /* Here we put a "hook" on the
    setTimeout() call by naming it.
    This allows the clearTimeout()
    call to know which one (there
    might be others) to stop. */
    tstop=setTimeou t("startIt()",s peed);
    }
    startIt()

    function stopIt(){
    clearTimeout(ts top);
    }
    startIt()
    // End Hiding -->
    </SCRIPT>
    startIt()
    </HEAD>
    <BODY BGCOLOR="white" ><CENTER>
    <P><B>Ginny & Eva tour Europe</B>
    <P><IMG SRC="5.jpg" height="350" NAME="ugly" BORDER="0">
    <P><FORM>


    <P><INPUT TYPE="button" NAME="b1" onClick="startI t()" VALUE=" Start
    Slide Show">
    startIt();
    <INPUT TYPE="button" NAME="b2" onClick="stopIt ()" VALUE=" Stop Slide
    show">
    </FORM>
    startIt()
    <P>Present delay (milliseconds):
    <IMG SRC="nr/1.gif" WIDTH="7" HEIGHT="10" BORDER="0">
    <IMG SRC="nr/0.gif" WIDTH="70" HEIGHT="10" BORDER="0">
    <IMG SRC="nr/0.gif" WIDTH="70" HEIGHT="10" BORDER="0">
    <IMG SRC="nr/0.gif" WIDTH="7" HEIGHT="10" BORDER="0">

    startIt()
    </BODY>
    startIt()
    </HTML>
  • rf

    #2
    Re: How to make a function run when web page loads.


    "TonyJeffs" <tonyjeffs@aol. com> wrote in message
    news:8ec4c623.0 309290317.23a57 7a3@posting.goo gle.com...[color=blue]
    >
    > When the page loads, you have to click the Start button to get the
    > slide show running, but I'd like it to start running straight away
    > without having to click.[/color]

    Er,
    <body ... onload="StartIt ()">

    Cheers
    Richard.


    Comment

    • TonyJeffs

      #3
      Re: How to make a function run when web page loads.

      "rf" <making.it.up@t he.time> wrote in message news:<kCUdb.129 035$bo1.21252@n ews-server.bigpond. net.au>...[color=blue]
      > "TonyJeffs" <tonyjeffs@aol. com> wrote in message
      > news:8ec4c623.0 309290317.23a57 7a3@posting.goo gle.com...[color=green]
      > >
      > > When the page loads, you have to click the Start button to get the
      > > slide show running, but I'd like it to start running straight away
      > > without having to click.[/color]
      >
      > Er,
      > <body ... onload="StartIt ()">
      >
      > Cheers
      > Richard.[/color]


      Thanks
      There's a logic to that!
      Maybe I should buy a book to get me underway.
      Does JS have public variables, and scope and stuff like that?

      Tony

      Comment

      Working...