Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Running Two (or more) Commands With onLoad

A common question we get is how to run two different commands with <BODY onLoad="...">. It's pretty simple: just put both of them in the onLoad attribute with a semicolon between them. It also might be simpler to put the commands in a separate function and call the function in onLoad.

For example, suppose you want to run this command when the document is loaded:

alert('Hello There!')

and you also want to run this command:

alert('Howdy!')

You can do this by putting them both in the onLoad attribute separated by a semicolon:

<BODY onLoad="alert('Hello There!'); alert('Howdy!')">

If you want to run more than two commands, just put semicolons in between all the commands. However, this tends to get messy, so it's usually a good idea to put the commands in a single function and call the function from onLoad. So, for example, you could create a function called init() by putting this script in the <HEAD> section of your page:

<SCRIPT TYPE="text/javascript">
function init()
{
alert('Hello There!');
alert('Howdy!');
}
//-->
</SCRIPT>

Then you can call init() with this onLoad attribute:

<BODY onLoad="init()">

 
 
  Copyright 1997-2002 Idocs inc. Published under the terms of the Open Content License Design by Interspire