HTML DOM - Events
Events are actions that can be detected by JavaScript.
Events
Every element on a web page has certain events which can trigger JavaScript
functions. For example, we can use the onClick event of a button element to
indicate that a function will run when a user clicks on the button. We define
the events in the HTML elements.
Examples of events:
- A mouse click
- A web page or an image loading
- Mousing over a hot spot on the web page
- Selecting an input box in an HTML form
- Submitting an HTML form
- A keystroke
Note: Events are normally used in combination with functions, and the
function will not be executed before the event occurs!
onload and onUnload
The onload and onUnload events are triggered when the user enters or leaves
a page.
The onload event is often used to check the visitor's browser type and
version, and load the proper version of the web page based on that
information.
Both the onload and onUnload events are also often used to deal with cookies
that should be set when a user enters or leaves a page. For example, you could
have a popup asking for the user's name upon his first arrival to your page. The
name is then stored in a cookie. Next time the visitor arrives at your page, you
could have another popup saying something like: "Welcome John Doe!".
onFocus, onBlur and onChange
The onFocus, onBlur and onChange events are often used in combination with
validation of form fields.
Below is an example of how to use an onChange event. The checkEmail()
function will be called whenever the user changes the content of the e-mail field:
|
E-mail:
<input type="text"
id="email" onchange="checkEmail()" />
|
Event Reference
For a complete description and examples of each event, see our HTML DOM Event reference.
Create a free Flash website with our simple, online web design editing platform. Stunning templates
and user-friendly tools make website building easy and fun.
Start Creating your free website now!

Need an easy way to get data into XML, or transform XML to another format?
MapForce lets you map XML data to/from any combination of XML, database, flat file,
Excel 2007, XBRL, or Web services data. Then it transforms data instantly or
auto-generates royalty-free code for recurrent conversions.
New features in Version 2010!
- Easy-to-use, graphical data mapping interface
- Instant data transformation
- XSLT 1.0/2.0 and XQuery code generation
- Java, C#, and C++ code generation
- Advanced data processing functions
- Support for all major relational databases including SQL Server, IBM DB2, Oracle, and more
- Visual Studio & Eclipse integration
- Available in 32-bit and 64-bit versions
Download a fully-functional trial today!
|
|
|
|