Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.

Slides:



Advertisements
Similar presentations
Chapter 08: Adding Adding Interactivity Interactivity With With Behaviors Behaviors By Bill Bennett Associate Professor MSJC CIS MVC.
Advertisements

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.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
JavaScript- Introduction. What it is and what it does? What it is? It is NOT Java It is NOT Server-side programming Users can see code It is a client-side.
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.
Introduction to Javascript. Web Page Technologies To create Web Page documents, you use: To create Web Page documents, you use: HTML – contents and structures.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
1 Events Lect 8. 2 Event-driven Pages one popular feature of the Web is its interactive nature e.g., you click on buttons to make windows appear e.g.,
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.
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.
Introduction to JavaScript. JavaScript Facts A scripting language - not compiled but interpreted line by line at run-time. Platform independent. It is.
KRAD makes it easy to handle HTML events in your webpage. Kuali University: Apply Now Lab 6: Fun with HTML Events Lab Objectives HTML Events – what are.
Chapter 19: Adding JavaScript
JavaScript Part 1.
1 JavaScript: Event Model November 1, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg.
CS346 Javascript-7A Events1 DOM Document Object Model and Events.
JavaScript 1. What is JavaScript? JavaScript allows web authors to create dynamic pages that react to user interaction. It is an Object-based because.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
Intro to JavaScript. Use the tag to tell the browser you are writing JavaScript.
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 AND DOM Internet Engineering Spring 2012.
 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.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
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.
Introduction To JavaScript. Putting it Together (page 11) All javascript must go in-between the script tags. All javascript must go in-between the script.
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.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
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.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
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.
Chapter 4 Java Script - Part1. 2 Outlines Introduction to Java Script Variables, Operators and Functions Conditional statements JavaScript Objects Forms.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
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.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
Methods and Object Information. Some Document Methods.
Week 4: Introduction to Javascript
Introduction to Javascript
Introduction to JavaScript Events
Web Development & Design Foundations with HTML5 7th Edition
JAVASCRIPTS AND HTML DOCUMENTS
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
CHAPTER 7 JavaScripts & HTML Documents
Web Design and Development
Introduction to Programming and JavaScript
JavaScript and Ajax (JavaScript Events)
Introduction to Web programming
Presentation transcript:

Event Handlers CS101 Introduction to Computing

Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where events can be handled on a page Find out what the events are in JavaScript Determine the event handlers that are used for each event Be able to code scripts that make use of event handlers

What is an Event? Something that happens when the User of the page performs some sort of action Possible actions –Mouse click –Mouse over An action triggers an event

What Is an Event Handler? Predefined JavaScript keyword Handles an event on a Web page –Identifies an event and then performs a specific task or set of tasks

Why Event Handlers Are Useful Enables Web page to react to an action by the User thus making scripts that are interactive and fun to use Example –Sending an alert to the User when he/she moves mouse over a link

Event Handler Locations and Uses …

Event Handler Locations Mostly used in –Form elements –Links –Body

Using Event Handlers Need to know keywords for event handlers and where to place event handler in script OnClick event handler –Used to make something happen when the User clicks something on the document

Problem 1 Display an alert message when the user clicks a button

Add the onClick event handler as an attribute to a form button Difference between and event handler attribute and HTML attribute –We can add JavaScript code inside an event handler attribute rather than just an attribute value Notice the quote marks –Double for code –Single for message (to avoid confusion with code)

Problem 2 Display alert messages when the user clicks a button

We can perform multiple actions on the script event We can code in two alerts and execute multiple commands Keep on one line between event handler keyword and semicolon –Line break could cause an error

<input type="button" onClick="window.alert('Hi');window.alert('Bye');">

<input type="button" onClick="window.alert('Hi');window.alert('Bye');">

Problem 3 Display alert messages when the user clicks a button using a function

If code is long, use a function Define function in head Call function from body This shortens code within event handler Can also reuse function elsewhere in a button or script

Events & Functions <!-- function hi_and_bye() { window.alert('Hi'); window.alert('Bye'); } //-->

Events & Functions <!-- function hi_and_bye() { window.alert('Hi'); window.alert('Bye'); } //-->

The Event Handlers Event Event handler Event trigger –Action that triggers event

EventEvent HandlerEvent Trigger ClickonClickUser clicks an area MouseoveronMouseOverUser moves the mouse over link MouseoutonMouseOutUser moves the mouse away from link LoadonLoadWeb page finishes loading UnloadonUnloadUser leaves current page FocusonFocusUser gives focus to something BluronBlurUser removes focus from something ChangeonChangeUser changes contents of form element SubmitonSubmitUser submits form on page

The Click Event (onClick) User clicks on an area Mainly used in form elements and links

Problem 4 Display an alert message when the user clicks on a button

onClick Event Handler <input type="button" value="Do not click here" onClick="window.alert('I told you not to click me!');">

Problem 5 Display an alert message when the user clicks on a link

onClick Event Handler Don't click me

The Mouseover Event (onMouseOver) User moves the mouse over an area Used in –Text link –Linked image

Problem 6 Display an alert message when the user moves mouse over a link

onMouseOver Event Handler Don't try clicking me!

The Mouseout Event (onMouseOut) User moves the mouse out of an area

Problem 7 Display an alert message when the user moves mouse away from a link

onMouseOut Event Handler Click me!

The Load Event (onLoad) Web page finishes loading

Problem 8 Display an alert message when the Web page finishes loading

onLoad Event Handler Body text.

The Unload Event (onUnload) Web page finishes loading

Problem 9 User leaves page

onUnload Event Handler Body text.

The Focus Event (onFocus) User gives focus to something

Problem 10 User gives focus to a text box

onFocus Event Handler Enter your name:

The Blur Event (onBlur) User removes focus from something

Problem 11 User gives focus to a first text box User removes focus from first text box User gives focus to second text box

onBlur Event Handler Give this text box focus: Then give this box focus to blur the first one:

What We Learnt Today... Learnt about event handlers Determined how events are useful in JavaScript Discovered where events can be handled on a page Found out what the events are in JavaScript Determined the event handlers that are used for each event Coded scripts that made use of event handlers