JavaScript forms mostly rely on events that occur on the form
due to user intervention. Events can be related to mouse, keyboard, or
web page such as onClick, onLoad, onFocus, ondblclick, or onSubmit. The
specific event handlers are associated with the events and invoke the
actions associated with the events. Event is the most important feature
of JavaScript because without events there will be no actions, no event
handlers, and therefore no code. Some important events are:
·
onLoad and onUnload: These events are related to the web
page and occur when the user enters and leaves the page respectively.
The onLoad event can be used to check the browser type and browser version
used by the user and get or set cookies on the user’s computer. The browser
check allows you to load the proper version of the web page and cookies
allow you to greet the users by their names.
·
onFocus, onBlur and onChange: These events allow you to handle
the webpage while the input fields validation. All these events are mostly
used in conjunction with each other. The onFocus event allows you to keep
the cursor on the field till the value is provided in it. The onBlur event
occurs when the focus is lost from a field and the onChange event occurs
when the value of a field is changed.
·
onSubmit: This event is the most important event and each form
has this event. It is actually used to validate all form fields before
submitting it. If the input values are correct then the form is finally
submitted.
·
onMouseOver and onMouseOut: These events are used to create
"animated" buttons. An alert box can be displayed when an onMouseOver
event is detected.
|