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
Solved

javascript automatic execution

Posted on 2004-03-20
5
1,211 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
multiple selects 23 48
Explain this javascript function to me 2 25
Button function on table is in trouble 3 20
on window close, not beforeunload 6 17
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

856 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