JavaScript: Introduction to Handling Events 20 th April 2011.

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.
The Web Warrior Guide to Web Design Technologies
NAMEd anchors Enabling users to jump to specific points within Web documents.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Cascading Style Sheets 23 rd March. Cascading Style Sheets (CSS) CSS Syntax Linking CSS to XHTML Inheritance & Cascading Order Font Properties Text Properties.
20-Jun-15 JavaScript and HTML Simple Event Handling.
Computer Science 103 Chapter 4 Advanced JavaScript.
Handling Events II 27th April Introduction Event Model Events Event Handling Navigation Events On-the-Fly Web Pages Web-Page Context Nesting On-the-Fly.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Lesson 2 Event Handling. Object Event Handlers Most of the objects that make up the Document Object Model respond to asynchronous, user generated events.
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.
5 th February Introduction Web Development Course.
CST JavaScript Validating Form Data with JavaScript.
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.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
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.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
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.
1 JavaScript: Event Model November 1, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg.
1 Goals and Objectives Goals Goals Understand how JavaScript makes it possible to interact with web pages, minimizes client/server traffic, enables verification.
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.
Forms. Forms Forms are used for e-commerce, online purchases, surveys, registrations, etc. Website using forms usually collect information and must use.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
DOM Events. JS Events Outline About Events – Introduction – Registering events – Getting information from events Event order/phases – Preventing default.
Tables 23 rd February. What XHTML have we done so far? Hyperlinks & anchors - XHTML supports 3 types of lists:  Ordered – +  Unordered – +  Definition.
Frames 2 nd March. Write the code for this using tables and using layers …..
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Introduction to the Document Object Model DOM *Understand document structure manipulation *Dynamic effects in web pages *Programming, scripting, web content.
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.
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
Thursday, August 6 th, 2015 Instructor: Craig Duckett Event Handling.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 4 Dynamic HTML & CSS.
DOM Events. JS Events Outline About Events – Introduction – Registering events – Getting information from events Event order/phases – Preventing default.
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.
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.
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 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.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Third lecture Event 27/2/2016 JavaScript Tutorial.
JavaScript and HTML Simple Event Handling 11-May-18.
Frames 8th March.
Chapter 14: DHTML: Event Model
Web Development & Design Foundations with HTML5 7th Edition
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
JavaScript Events.
CHAPTER 7 JavaScripts & HTML Documents
JavaScript and Ajax (JavaScript Events)
JAVA SCRIPT OBJECTS & DOM
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

JavaScript: Introduction to Handling Events 20 th April 2011

Introduction Event Model Events Event Handling

Event Model Event model is based on interaction between a web surfer and a web page Events can be classified into two broad groups:  Navigation: clicking on links to browse through web pages  Filling a form: entering data and checking form elements JavaScript event model is based on event object event object connects event source to event handler When an event occurs, JavaScript sends event object to event handler

Event Model The properties of event object may be: type, target, width, height, layerX, layerY, pageX, pageY,screenX, screenY, data, modifiers, which

Event Model

Program that prints all the properties of event object

Events JavaScript has a unique event for each event source: Event name Event Source Event handler abort image onAbort click text field/area, list onChange dragDrop window onDragDrop error image, window onError keyDown doc, image, link onKeyDown keyPress doc, image, link onKeyPress mouseMove nothing onMouseMove mouseOut link, image map onMouseOut mouseOver link, image map onMouseOver reset reset button form onReset resize window onResize submit submit button form onSubmit

Events function listAllProps(evt){ str="type= " +evt.type+"\n"; alert(str); } List all properties of JavaScript event object

Events JavaScript has a unique event for each event source: Event name Event Source Event handler abort image onAbort click checkbox, radio button,onClick submit button, reset button & link changetext field/area, list onChange dragDrop window onDragDrop error image, window onError keyDown doc, image, link onKeyDown keyPress doc, image, link onKeyPress mouseMove nothing onMouseMove mouseOut link, image map onMouseOut mouseOver link, image map onMouseOver reset reset button form onReset resize window onResize submit submit button form onSubmit

Event Handling Event handlers handle and process events Event handler is included as an attribute of a XHMTL tag  Event handlers must be enclosed in quotes Handlers are executed first, then XHTML content is rendered Event handlers can be written as:  Inline script: JavaScript code is included inside XHTML tag  Function call: event handlers are written as functions in tag and called from the XHTML tag Function call style is better than inline style

Event Handling Event handlers handle and process events Event handler is included as an attribute of a XHMTL tag  Event handlers must be enclosed in quotes Handlers are executed first, then XHTML content is rendered Event handlers can be written as:  Inline script: JavaScript code is included inside XHTML tag  Function call: event handlers are written as functions in tag and called from the XHTML tag Function call style is better than inline style Event Handlers “glue” XHTML and JavaScript together

Reference Steven M. Schafer (2005), HTML, CSS, JavaScript, Perl, and PHP Programmer's Reference, Hungry Minds Inc,U.S. Dan Cederholm (2005), Bulletproof Web Design: Improving Flexibility and Protecting Against Worst-Case Scenarios with XHTML and CSS, New Riders. Ibrahim Zeid (2004), Mastering the Internet, XHTML, and Javascript

<html><head> JavaScript Example JavaScript Example </head><body> The Javascript Back Button! The Javascript Back Button! <form> </form><br><br></body></html>

Another example.. Don't click this link!

Another example.. var browserName=navigator.appName; if (browserName=="Netscape") { alert("Hi Netscape User!"); } else { if (browserName=="Microsoft Internet Explorer") { alert("Hi, Explorer User!"); } else { alert("What ARE you browsing with here?"); } }

Another example.. Don't click this link!