473,721 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>
Jul 20 '05 #1
2 7081
rf

"TonyJeffs" <to*******@aol. com> wrote in message
news:8e******** *************** ***@posting.goo gle.com...

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.


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

Cheers
Richard.
Jul 20 '05 #2
"rf" <ma**********@t he.time> wrote in message news:<kC******* *************@n ews-server.bigpond. net.au>...
"TonyJeffs" <to*******@aol. com> wrote in message
news:8e******** *************** ***@posting.goo gle.com...

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.


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

Cheers
Richard.

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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2665
by: Edward King | last post by:
Hi! I am trying to achieve the following: I have a number of help pages (in the format help_nn.php where nn=helpid). I want to be able to open a particular help page by calling the function gethelp(nn) where nn is the helpid. The function is contained in a header file called funcs.inc that each page
4
2764
by: Yvan J. Gagnon | last post by:
I am encountering a strange problem in Netscape 7 with a CFM file I am trying to troubleshoot (the page is working fine in NS Communicator and IE). Below is a sample of the problematic line of javascript code. Note that in the actual file, I've surrounded the variable '#cookie.cookiename#' with CFOUTPUT tags: document.write('<input type="Hidden" name="affiliate" value="#cookie.cookiename#">'); When I load the document in Netscape 7, I...
9
1915
by: Dom | last post by:
I have a frameset with a left right columns, called 'index' and 'content'. The left column of the frameset ('index') loads an index.htm file which have these hrefs (summarized the code a bit) for readability : <a href="studio/index.htm" target=content id="studio"> studio </a> <a href="bandw/index.htm" target=content id="bandw"> bandw </a> <a href="arch/index.htm" target=content id="arch"> arch </a> <a href="etc/index.htm" ...
11
2711
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
2
2658
by: shree | last post by:
Hi all, I'm trying to call javascript function via onLoad but running into a problem. I would appreciate any help and suggestion. My application is as follows. When a page loads, I want to check whether the vistor has the site's cookie present in their browser. If its not present, then to redirect user to a login page (script). If the cookie is present, then the rest of the html page should load. I'm able to get function to detect...
9
13608
by: finerrecliner | last post by:
i'm trying to make an action listener that will display an alert box when the user clicks anywhere on the page once, and then go back to normal mouse behavior. i have this: <html><script type="text/javascript"> document.addEventListener('click',hello(),false); function hello() { alert("hello world!")
7
3572
by: Schmidty | last post by:
Okay...I have another 'newbie' question; I have a function that loads a page and the action is $_SERVER; In the form that is in a function(method?) within a class a variable is passed back to a mysqli connection and database and updates the database. The problem is that when the page is reloaded it does not show the updated information in the database with the $_SERVER. Why is the page loaded with the same information? Is it cached...
2
2675
by: Yi | last post by:
I want to make a simple javascript widget, something looks like the Google AdWords, that people can just post a small section of code on their web page and display some content from my website. I searched online and found many javascript tools and packages but all seem to be building widgets for a widget platform. I want something that anybody can just copy and paste on their web page no matter they are using ASP.NET or html or PHP for...
1
3182
by: jntmac | last post by:
I cannot find the answer anywhere on the entire net: I have an image on my website. The image shows a newsletter, and the image says "Click here to register to receive our newsletter". I know how to make the image link to a url, but I don't want to do that. What I want to do is when you click on the image, it calls an external javascript function that brings up a popup where you enter your name and email address and submit. The external...
0
8840
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3189
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.