Internet & World Wide Web How to Program, 5/e. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

Slides:



Advertisements
Similar presentations
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Advertisements

CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
The Web Warrior Guide to Web Design Technologies
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Tutorial 15 Working with the Event Model. XP Objectives Compare the IE and W3C event models Study how events propagate under both event models Write a.
20-Jun-15 JavaScript and HTML Simple Event Handling.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
XP Tutorial 8 New Perspectives on JavaScript, Comprehensive1 Working with the Event Model Creating a Drag-and-Drop Shopping Cart.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Events.
CST JavaScript Validating Form Data with JavaScript.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Chapter 5 © 2003 by Addison-Wesley, Inc. 1 Chapter 5 JavaScript and HTML Documents.
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
Chapter 5 JavaScript and HTML Documents. © 2006 Pearson Addison-Wesley. All rights reserved JavaScript Execution Environment - The JavaScript.
JavaScript Part 1.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 JavaScript and HTML Documents.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
JavaScript, Part 3 Instructor: Charles Moen CSCI/CINF 4230.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Dynamic HTML: Event Model Outline 16.1Introduction 16.2Event ONCLICK 16.3Event ONLOAD.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload.
JavaScript - A Web Script Language Fred Durao
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
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.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Dialog boxes in JavaScript Events in JavaScript – What are they – “Which events are there?” – “How do I register event handlers to an HTML element?” –
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
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.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 4 Dynamic HTML & CSS.
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.
Rich Internet Applications 3. Client JavaScript. Document Object Model (DOM) The DOM, is an interface that allows scripts or programs to access and manipulate.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 5. JavaScript and HTML Documents.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
Event Handling & AJAX IT210 Web Systems. Question How do we enable users to dynamically interact with a website? Answer: Use mouse and keyboard to trigger.
Host Objects: Browsers and the DOM
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
Events Event Handling in JavaScript SoftUni Team Technical Trainers Software University
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.
This is our seminar JavaScript And DOM This is our seminar JavaScript And DOM.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Jozef Goetz contribution, © by Pearson Education, Inc. All Rights Reserved.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
REEM ALMOTIRI Information Technology Department Majmaah University.
JavaScript and HTML Simple Event Handling 11-May-18.
Introduction to JavaScript Events
JavaScript Functions.
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and Events.
JavaScript and HTML Simple Event Handling 19-Sep-18.
13 JavaScript: Events.
JavaScript and HTML Documents
Events Comp 205 Fall 2017.
CHAPTER 7 JavaScripts & HTML Documents
Events.
JavaScript and Events CS Programming Languages for Web Applications
CHAPTER 6 EVENTS. CHAPTER 6 EVENTS WHAT IS AN EVENT?
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and Events CS Programming Languages for Web Applications
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Internet & World Wide Web How to Program, 5/e

© by Pearson Education, Inc. All Rights Reserved.

 JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events and event handling  help make web applications more dynamic and interactive © by Pearson Education, Inc. All Rights Reserved.

 The window object’s load event fires when the window finishes loading successfully (i.e., all its children are loaded and all external files referenced by the page are loaded)  Every DOM element has a load event, but it’s most commonly used on the window object.  The next example reviews the load event.  The load event’s handler creates an interval timer that updates a span with the number of seconds that have elapsed since the document was loaded. The document’s paragraph contains the span. © by Pearson Education, Inc. All Rights Reserved.

 An event handler is a function that responds to an event.  Assigning an event handler to an event on a DOM node is called registering an event handler  Method addEventListener can be called multiple times on a DOM node to register more than one event-handling method for an event.  It’s also possible to remove an event listener by calling removeEventListener with the same arguments that you passed to addEventListener to register the event handler.  If a script in the head attempts to get a DOM node for an HTML element in the body, getElementById returns null because the body has not yet loaded © by Pearson Education, Inc. All Rights Reserved.

 Two models for registering event handlers  Inline model treats events as attributes of HTML elements  Traditional model assigns the name of the function to the event property of a DOM node  The inline model places calls to JavaScript functions directly in HTML code.  The following code indicates that JavaScript function start should be called when the body element loads:  The traditional model uses a property of an object to specify an event handler.  The following JavaScript code indicates that function start should be called when document loads: document.onload = "start()"; © by Pearson Education, Inc. All Rights Reserved.

 mousemove event occurs whenever the user moves the mouse over the web page  The next example creates a simple drawing program that allows the user to draw inside a table element in red or blue by holding down the Shift key or Ctrl key and moving the mouse over the box.  ctrlKey property contains a boolean which reflects whether the Ctrl key was pressed during the event  shiftKey property reflects whether the Shift key was pressed during the event © by Pearson Education, Inc. All Rights Reserved.

 When the mouse cursor enters an element, an mouseover event occurs for that element  When the mouse cursor leaves the element, a mouseout event occurs for that element  Creating an Image object and setting its src property preloads the image © by Pearson Education, Inc. All Rights Reserved.

 focus event fires when an element gains focus  i.e., when the user clicks a form field or uses the Tab key to move between form elements  blur fires when an element loses focus  i.e., when another control gains the focus © by Pearson Education, Inc. All Rights Reserved.

 submit and reset events fire when a form is submitted or reset, respectively  The anonymous function executes in response to the user’s submitting the form by clicking the Submit button or pressing the Enter key.  confirm method asks the users a question, presenting them with an OK button and a Cancel button  If the user clicks OK, confirm returns true ; otherwise, confirm returns false  By returning either true or false, event handlers dictate whether the default action for the event is taken  If an event handler returns true or does not return a value, the default action is taken once the event handler finishes executing © by Pearson Education, Inc. All Rights Reserved.

 Event bubbling  The process whereby events fired on child elements “bubble” up to their parent elements  When an event is fired on an element, it is first delivered to the element’s event handler (if any), then to the parent element’s event handler (if any)  If you intend to handle an event in a child element alone, you should cancel the bubbling of the event in the child element’s event-handling code by using the cancelBubble property of the event object © by Pearson Education, Inc. All Rights Reserved.

 The following slide lists some common events and their descriptions. The actual DOM event names begin with " on ", but we show the names you use with addEventListener here. © by Pearson Education, Inc. All Rights Reserved.