JavaScript Events
Events are actions that can be detected by JavaScript.
Events
By using JavaScript, we have the ability to create dynamic web pages. Events are actions that can be detected by JavaScript.
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 tags.
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!
For a complete reference of the events recognized by JavaScript, go to our
complete Event reference.
onload and onUnload
The onload and onUnload events are triggered when the user enters or leaves
the page.
The onload event is often used to check the visitor's browser type and
browser version, and load the proper version of the web page based on the
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 the onChange event. The checkEmail()
function will be called whenever the user changes the content of the field:
<input type="text" size="30"
id="email" onchange="checkEmail()">
|
onSubmit
The onSubmit event is used to validate ALL form fields
before submitting it.
Below is an example of how to use the onSubmit event. The checkForm()
function will be called when the user clicks the submit button in the form. If the
field values are not accepted, the submit should be
cancelled. The function checkForm() returns either true or false. If it returns true the
form will be submitted, otherwise the submit will be cancelled:
<form method="post" action="xxx.htm"
onsubmit="return checkForm()">
|
onMouseOver and onMouseOut
onMouseOver and onMouseOut are often used to create
"animated" buttons.
Below is an example of an onMouseOver event. An alert box appears when an onMouseOver
event is detected:
<a href="http://www.w3schools.com"
onmouseover="alert('An onMouseOver event');return false">
<img src="w3schools.gif" width="100" height="30">
</a>
|
Make your web applications look like a million bucks
|
|
Most web applications today use boring methods to present data to their viewers using grids or simple HTML tables. FusionCharts induces "life" into the web applications by converting monotonous data into lively charts, gauges & maps.
FusionCharts works with all technologies like ASP, ASP.NET, PHP, ColdFusion, Ruby on Rails, JSP, HTML pages etc.
and connects to any database to render animated & interactive charts. It takes less than 15 minutes and no expertise
whatsoever to build your first chart and just a glance of it to captivate your audience. This fact is endorsed by our
12,000 customers and 150,000 users which include a majority of the Fortune 500 companies.
And yeah, your applications could look like a million bucks by spending just $69.
So go ahead, download your
copy of FusionCharts and start "wow-ing" your customers now!
|
|