0% found this document useful (0 votes)
32 views2 pages

18 Events

JavaScript Events allow actions on a webpage to be detected. Common events include mouse clicks, loading of content, form submissions, and keystrokes. Events are often used with functions to trigger dynamic behavior on a webpage, such as validating form fields on submit. Key events include onload, onclick, onsubmit, onmouseover and onmouseout.

Uploaded by

BaneeIshaqueK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

18 Events

JavaScript Events allow actions on a webpage to be detected. Common events include mouse clicks, loading of content, form submissions, and keystrokes. Events are often used with functions to trigger dynamic behavior on a webpage, such as validating form fields on submit. Key events include onload, onclick, onsubmit, onmouseover and onmouseout.

Uploaded by

BaneeIshaqueK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

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 a JavaScript. For example, we
can use the onClick event o a button element to indicate that a unction will run when a user clicks
on the button. !e deine the events in the "#$% tags.
Examples o events&
' mouse click
' web page or an image loading
$ousing over a hot spot on the web page
Selecting an input ield in an "#$% orm
Submitting an "#$% orm
' keystroke
Note: Events are normally used in combination with unctions, and the unction will not be executed
beore the event occurs(
For a complete reerence o the events recogni)ed by JavaScript, go to our complete Event
reerence.
on%oad and on*nload
#he on%oad and on*nload events are triggered when the user enters or leaves the page.
#he on%oad event is oten used to check the visitor+s browser type and browser version, and load
the proper version o the web page based on the inormation.
Both the on%oad and on*nload events are also oten 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 or the user+s
name upon his irst arrival to your page. #he name is then stored in a cookie. ,ext time the visitor
arrives at your page, you could have another popup saying something like& -!elcome John .oe(-.
onFocus, onBlur and onChange
#he onFocus, onBlur and onChange events are oten used in combination with validation o orm
ields.
Below is an example o how to use the onChange event. #he checkEmail/0 unction will be called
whenever the user changes the content o the ield&
<input type="text" size="30" id="email" onchange="checkEmail()">
onSubmit
#he onSubmit event is used to validate '%% orm ields beore submitting it.
Below is an example o how to use the onSubmit event. #he checkForm/0 unction will be called
when the user clicks the submit button in the orm. 1 the ield values are not accepted, the submit
should be cancelled. #he unction checkForm/0 returns either true or alse. 1 it returns true the orm
will be submitted, otherwise the submit will be cancelled&
<form method="post" action="xxxhtm" onsu!mit="return check"orm()">
on$ouse2ver and on$ouse2ut
on$ouse2ver and on$ouse2ut are oten used to create -animated- buttons.
Below is an example o an on$ouse2ver event. 'n alert box appears when an on$ouse2ver event
is detected&
<a href="http#$$%%%%3schoolscom" onmouseo&er="alert('(n on)ouse*&er
e&ent')+return false"><img src="%3sgif" alt=",3-chools" $><$a>

You might also like