Connecting Tech Pros Worldwide Help | Site Map

How to make a function run when web page loads.

  #1  
Old July 20th, 2005, 11:50 AM
TonyJeffs
Guest
 
Posts: n/a
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>Holiday</TITLE>

<SCRIPT LANGUAGE="JavaScript">
<!-- 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.src=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=setTimeout("startIt()",speed);
}
startIt()

function stopIt(){
clearTimeout(tstop);
}
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="startIt()" 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>
  #2  
Old July 20th, 2005, 11:50 AM
rf
Guest
 
Posts: n/a

re: How to make a function run when web page loads.



"TonyJeffs" <tonyjeffs@aol.com> wrote in message
news:8ec4c623.0309290317.23a577a3@posting.google.c om...[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.


  #3  
Old July 20th, 2005, 11:51 AM
TonyJeffs
Guest
 
Posts: n/a

re: How to make a function run when web page loads.


"rf" <making.it.up@the.time> wrote in message news:<kCUdb.129035$bo1.21252@news-server.bigpond.net.au>...[color=blue]
> "TonyJeffs" <tonyjeffs@aol.com> wrote in message
> news:8ec4c623.0309290317.23a577a3@posting.google.c om...[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
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validating Javascript function using JLint phpentrylevel@googlemail.com answers 2 November 15th, 2008 12:45 AM
[newbie] How to make simple JavaScript widget Yi answers 2 July 12th, 2008 10:25 AM
Set a value to a hidden field in a web page Magnus Blomberg answers 4 November 19th, 2005 09:44 AM
Trouble with system() function Penn Markham answers 9 July 17th, 2005 05:43 AM