You are on page 1of 12

Presented by : Prof. Varsha Tank (IT/ICT Dept.

- LJIET)
UNIT – 3
JAVA SCRIPT
Topics to be covered
 Event Handling
 Examples
Event Handling
 What is an Event ?
 JavaScript's interaction with HTML is handled through events that
occur when the user or the browser manipulates a page.
 When the page loads, it is called an event. When the user clicks a
button, that click too is an event. Other examples include events like
pressing any key, closing a window, resizing a window, etc.
 Developers can use these events to execute JavaScript coded
responses, which cause buttons to close windows, messages to be
displayed to users, data to be validated, and virtually any other
type of response imaginable.
 Events are a part of the Document Object Model (DOM) Level 3 and
every HTML element contains a set of events which can trigger
JavaScript Code.
Event Handling – cont.
Event Belongs To Description

blur FocusEvent The event occurs when an element loses focus

change Event The event occurs when the content of a form element,
the selection, or the checked state have changed (for

<input>, <select>, and <textarea>)


click MouseEvent The event occurs when the user clicks on an element

dblclick MouseEvent The event occurs when the user double-clicks on an


element

focus FocusEvent The event occurs when an element gets focus

keydown KeyboardEvent The event occurs when the user is pressing a key

keypress KeyboardEvent The event occurs when the user presses a key

keyup KeyboardEvent The event occurs when the user releases a key
Event Handling – cont.
Event Belongs To Description
load UiEvent, Event The event occurs when an object has loaded
mousedown MouseEvent The event occurs when the user presses a mouse button
over an element
mousemove MouseEvent The event occurs when the pointer is moving while it is
over an element
mouseover MouseEvent The event occurs when the pointer is moved onto an
element, or onto one of its children
mouseout MouseEvent The event occurs when a user moves the mouse pointer
out of an element, or out of one of its children
mouseup MouseEvent The event occurs when a user releases a mouse button
over an element
reset Event The event occurs when a form is reset

submit Event The event occurs when a form is submitted

unload UiEvent, Event The event occurs once a page has unloaded (for

<body>)
Examples
1. Design HTML form which include two fields username and password. Write
JavaScript code to show and hide password
Examples –cont.
2. Write a Javacript to know number of elements in
the form.
Examples –cont.
2. Write a JavaScript that handles following
events:
 Gives the key code for the key pressed.
 The script should give message that “vowel is
pressed” if vowel keys are pressed.
 Background colour should change to red after
releasing the pressed key.
Examples –cont.
Summary
 Event Handling
 Examples

You might also like