Solved

javascript automatic execution

Posted on 2004-03-20
5
1,212 Views
Last Modified: 2012-08-13
I have
<script>
 //javascript functions
</script>

1. Is there a way to run one of the functions automatically whenever the page is loaded, besides BODY onLoad event ??

2. Is there in javascript Sleep function that  makes thread to sleep for given time?
0
Comment
Question by:amakalski
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10641970
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
window.onload = function(){
      // Do your onload statements here
      alert("Some onload function is running");
      setTimeout("alert('I was sleeping for just a few :)')", 700);
}
// -->
</script>
</head>

<body>

</body>
</html>
0
 
LVL 16

Assisted Solution

by:jaysolomon
jaysolomon earned 75 total points
ID: 10641974
setTimeout would be like a sleep copy paste and see results
0
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 75 total points
ID: 10642045
For your first question.... you can directly do the function call without onload() function..

<script>

welcomeuser();

 function welcomeuser()
 {
    alert("welcome...");
 }

</script>
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10642384
Adding on to what venkateshwarr said...

If you want to wait until the page COMPLETELY loaded, make sure you put venkateshwarr's code at the very bottom of your page. If you don't, you might get an error. For example, the following code throws an error because the script runs before the form has loaded.

<script>
welcomeuser();
function welcomeuser(){
document.forms[0].welcome.value="Welcome!";
}
</script>

<form>
<input type=text name=welcome>
</form>
0
 
LVL 15

Expert Comment

by:JakobA
ID: 10642741
Also you should not call the function before you define it:

<script>
function welcomeuser(){    // defines the function
    document.forms[0].welcome.value="Welcome!";
}
          // now the function has been defined so we can call it:
welcomeuser();
</script>
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question