Lesson 2 Event Handling. Object Event Handlers Most of the objects that make up the Document Object Model respond to asynchronous, user generated events.

Slides:



Advertisements
Similar presentations
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
Advertisements

JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Session 11 Dynamic HTML: Event Model and Filters Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
The Web Warrior Guide to Web Design Technologies
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
JavaScript Forms Form Validation Cookies CGI Programs.
20-Jun-15 JavaScript and HTML Simple Event Handling.
Computer Science 103 Chapter 4 Advanced JavaScript.
Advanced Javascript Dick Steflik Binghamton University.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
JavaScript Client Side scripting. Client-side Scripts Client-side scripts, which run on the user’s workstation can be used to: Validate user inputs entered.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Events.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript forms.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
JavaScript - a Brief Introduction Anupriya. What is JavaScript Object based (not object oriented) programming language –very limited object creation –a.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Chapter 19: Adding JavaScript
Chapter 5 © 2003 by Addison-Wesley, Inc. 1 Chapter 5 JavaScript and HTML Documents.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
Chapter 5 JavaScript and HTML Documents. © 2006 Pearson Addison-Wesley. All rights reserved JavaScript Execution Environment - The JavaScript.
1 JavaScript: Event Model November 1, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
1 Dynamic HTML III: Event Model Introduction Event model –Scripts respond to user actions and change page accordingly Moving mouse Scrolling screen.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Dynamic HTML: Event Model Outline 16.1Introduction 16.2Event ONCLICK 16.3Event ONLOAD.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Chapter 5 © 2005 by Addison Wesley Longman, Inc JavaScript Execution Environment - The JavaScript Window object represents the window in which the.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
Chapter 14: Dynamic HTML: Event Model Presented by: Colbie Brown CS340 Java Web Development Dr. Gloria Carter Love.
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Thursday, August 6 th, 2015 Instructor: Craig Duckett Event Handling.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Dynamic HTML: Event Model Outline 16.1Introduction 16.2Event ONCLICK 16.3Event ONLOAD.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
Project 8: Reacting to Events Essentials for Design JavaScript Level One Michael Brooks.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
Web Programming Java Script & jQuery Web Programming.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
H.Melikyan/4910/031 Programming the World Wide Web JavaScript Dr.Hayk Melikyan Departmen of Mathematics and CS JavaScript and HTML Documents.
JS DOM. Introduction An HTML page is rendered (painted) in a browser The browser assembles all the elements (objects) contained in the HTML page To create.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
Event Handlers Events are asynchronous. When an event occurs, JavaScript can execute code in response to the user’s action. This response to the user-initiated.
20-753: Fundamentals of Web Programming 1 Lecture 13: Javascript II Fundamentals of Web Programming Lecture 13: Javascript II.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Methods and Object Information. Some Document Methods.
5.1 JavaScript Execution Environment
JavaScript and HTML Simple Event Handling 11-May-18.
JavaScript - a Brief Introduction
Introduction to JavaScript Events
Chapter 14: DHTML: Event Model
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
Dick Steflik Binghamton University
CHAPTER 7 JavaScripts & HTML Documents
JavaScript and Ajax (JavaScript Events)
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Lesson 2 Event Handling

Object Event Handlers Most of the objects that make up the Document Object Model respond to asynchronous, user generated events through predefined event handlers that handle the event and transfer control to a user provided event handling function Each object has particular events that they will respond to the way you specify an event handler is by adding an additional attribute to the HTML tag that specifies the event and the particular handler –if the button is click the function abc( ) will be run

Alert The “Alert” function is useful in user notification and debugging of Javascripts. Pops up a message in a pop-up dialog box Ex, alert(“help, help, help”);

Events onAbort onBlur onChange onClick onError onFocus onLoad onMouseOut onMouseOver onReset onSelect onSubmit onUnload

onAbort Activated when a user aborts the loading of an image

onBlur Used with frame, select, text, textarea and window objects invoked when an object loses focus use with select, text and textarea for data validation

onChange Used with select, text and textarea objects use instead of onBlur to validate only if a value has changed Color: Red Green Blue

onClick Used with button, checkbox,link, radio, reset, and submit objects.

onError Used with image and window objects to invoke a handler if an error occurs while an image or window is loading. Setting window.onerror = null will prevent users from seeing JavaScript generated errors

onFocus Used with frame, select, text, textarea and window objects. Just the opposite of onBlur; i.e. invoked when the object gets focus.

onLoad Used with window, frame and image objects (use with and ) Activated when the body, frameset, or image is loaded

onMouseOut and onMouseOver Used with area and link objects user moves mouse off of an area or link <area name=top coords=“0,0,200,300 href=“javascript:displayMessage()” onMouseOver=“self.status=‘when you see this message click your left mouse button’ ; return true” onMouseOut=“self.status = ‘’ ; return true”>

onReset Used with form objects

onSelect Used with text and textarea objects run some Javascript whenever a user selects a piece of text in a text or textarea object

onSubmit Use with form objects to run a handler whenever a form has been submitted. Usefull to validate all fields prior to actual submission

onUnload Just like onLoad but the handler is run when the window/frame is exited

Advanced Event Handling Previous events are event objects caused as a result of interaction with forms tags There is another Event object made necessary by the advent of Dynamic HTML –allows a more powerful way of trapping and processing events

The Event Object Provides a set of properties (no methods) that event handling routines use as constants –property group 1 (modifier keys ) Alt –Event.ALT_MASK Ctrl –Event.CONTROL_MASK Shift –Event.SHIFT_MASK Meta (Windows key, or Command key on Mac) –Event.META_MASK –property group 2 (other event types ) one property for each event type in DOM –ex. Event.CLICK //generic click event

Capturing Events Remember the hierarchy: window linkanchorlayerformappletimagearea historydocumentlocationtoolbar textradiobuttonfileUploadselect textarea password checkboxreset submit option

Capturing Events (cont) Window, document and layers all have a captureEvents( ) method the methods require one or more parameters that will tell it which events to capture; do this as the page loads (head section is good) –window.captureEvents(Event.KEYPRESS) –window.captureEvents(Event.KEYPRESS) | Event.CLICK) assign a function to handle the captured event –window.onClick = processClick

Turning event capture off To turn event capture off use the releaseEvents( ) method use the same parameters as captureEvents( )

Event Forwarding Use your generalized event handler (for all clicks) to do high level processing and then allow the individual handlers do their job for the specific events by using routeEvent(e) to pass the event through the hierarchy to the target handler. This let you minimize the amount of code you would repeat in writing the handlers this lets your events to travel through the hierarchy automatically this works different for Netscape and Internet Explorer –in Netscape events travel down the hierarchy to the target; in IE they travel up the hierarchy (from the object to the window) –in Netscape events are only generated by forms objects and a few others; in IE almost any tag can generate an event

handleEvent The handleEvent(e) method allows you to route and event to anywhere in the hierarcy, regardless of the hierarchy. the object reference is the reference of the object to handle the event; passing the event object as a parameter, like routeEvent and captureEvent as long as the target object as an event handler it will process it just as if it had received it directly from the system

Problems The event model is not standardized across all browsers, just as dynamic HTML is far from standardized. Forewarned is forearmed, this is a place where you could really get into trouble because of browser incompatibilities.