SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.

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.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
20-Jun-15 JavaScript and HTML Simple Event Handling.
Computer Science 103 Chapter 4 Advanced JavaScript.
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.
UNIT 6 JAVASCRIPT EVENT HANDLERS &WEB BROWSERS DETECTION.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
1 JavaScript: Event Model November 1, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload 14.4.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
DOM Events. JS Events Outline About Events – Introduction – Registering events – Getting information from events Event order/phases – Preventing default.
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
1 JavaScript 2 JavaScript. 2 Rollovers Most web page developers first use JavaScript for rollovers A rollover is a change in the appearance of an element.
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.
Thursday, August 6 th, 2015 Instructor: Craig Duckett Event Handling.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 14 - Dynamic HTML: Event Model Outline 14.1 Introduction 14.2 Event onclick 14.3 Event onload 14.4.
 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.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
JavaScript Functions A function is a block of code that can be reused. It is similar to a method in Java. It consists of a function name, an argument.
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.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
JavaScript Events.
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.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Methods and Object Information. Some Document Methods.
Third lecture Event 27/2/2016 JavaScript Tutorial.
5.1 JavaScript Execution Environment
JavaScript and HTML Simple Event Handling 11-May-18.
Week 3: Introduction to Javascript
Week 4: Introduction to Javascript
Introduction to JavaScript Events
Web Development & Design Foundations with HTML5 7th Edition
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
Chapter 14 - Dynamic HTML: Event Model
JavaScript Events.
13 JavaScript: Events.
DHTML Javascript Internet Technology.
JavaScript and HTML Documents
DHTML Javascript Internet Technology.
CHAPTER 7 JavaScripts & HTML Documents
Functions, Regular expressions and Events
Web Design and Development
Code Topic 9 Standard JavaScript Events Laura Friedman
JavaScript and Events CS Programming Languages for Web Applications
JavaScript and Ajax (JavaScript Events)
Web Programming and Design
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects

Dynamic HTML is about scripting the DOM to change a web page document after it is loaded into a browser SE-2840 Dr. Mark L. Hornick 2 But how do you know when the browser has finished loading the document?

SE-2840 Dr. Mark L. Hornick 3 Javascript code hosted in a browser can be triggered to run in response to Events Events are triggered by Browser actions Page load/unload Offline/Online ….many more User actions within a page Button press Mouse-over/click Text entry Input focus/blur …many more See

SE-2840 Dr. Mark L. Hornick 4 Some events associated with HTML elements Window events (valid only in elements) onload – generated when browser navigates to the page onunload – …when browser navigates away Input element events onblur – …when an element loses keyboard focus onchange – …when a [text] element changes onfocus – …when an element gains keyboard focus onreset – …when “reset”-type pushbutton pressed onsubmit – …when “submit”-type pushbutton pressed Mouse Events (validity restricted to certain elements) onmouseover – …when cursor passes onto an element onmouseout – …when cursor passes off an element onclick – …when a button (or other element) is pressed Keyboard Events (validity restricted to certain elements) onkeydown – …when a key is pressed onkeyup – …when a key is released onkeypress – …after a key is pressed and then released See

SE-2840 Dr. Mark L. Hornick 5 There are several ways to add JavaScript to a button. Method A: onclick specified in HTML The onclick attribute specifies the JavaScript code that will be executed when the button is pressed. In this case, the code to be executed is the call to the onClickHandler() function. The onClickHandler() method must have been defined or linked to from within the section of the page. Note the ( ) following the method name! These are required!!!

SE-2840 Dr. Mark L. Hornick 6 Method B: onclick specified in script The onclick attribute specifies the address of the JavaScript function that will be called when the button is pressed. Be sure not to supply ( ) after the function – otherwise, the result of calling the function, rather than the function address, will be used. The script that calls getElementById must execute AFTER the page loads to make sure that the button element actually exists! Thus, getElementById is usually placed in the window.onload handler //Code that executes after page loads: var button = getElementById(“goButton”); button.onclick = onClickHandler; // omit () !!!

What if we only wanted a single event handler to handle multiple events, or even multiple events from multiple sources? SE-2840 Dr. Mark L. Hornick 7 The window.event object can be passed as an argument to an event handler

Properties of the event object type – a string containing the name of the event The onclick event type is “click”, onmouseover is “mouseover”, etc. target – a reference to the element that caused the event CS-422 Dr. Mark L. Hornick 8