Page 179 - DCAP408_WEB_PROGRAMMING
P. 179
Unit 6: DOM Model
4. ………………… does not provide all of the features of a full object oriented programming Notes
language.
5. JSSS use JavaScript syntax to control a ………………… presentation style.
6. All ………………… on a web page are not created equal.
7. JavaScript enabled browser and JavaScript most of major web page objects are
…………………
6.2 Events Handling through JavaScript
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 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 are:
A mouse click
A web page or an image loading
Mousing over a hot spot on the web page
Selecting an input field in an HTML form
Submitting an HTML form
A keystroke.
Notes 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 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 upendra!”.
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()”>
LOVELY PROFESSIONAL UNIVERSITY 173