Dialog boxes in JavaScript Events in JavaScript – What are they – “Which events are there?” – “How do I register event handlers to an HTML element?” –

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

The Web Warrior Guide to Web Design Technologies
Information Technology Center Hany Abdelwahab Computer Specialist.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
JavaScript, Fourth Edition
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
Mr C Johnston ICT Teacher BTEC IT Unit 06 - Lesson 02 Types of Programming Language.
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.
JavaScript Lecture 6 Rachel A Ober
Arrays – What is it? – Creation – Changing the contents Functions – What is it? – Syntax – How they work – Anonymous functions A quick lesson in Objects.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
JavaScript, Part 3 Instructor: Charles Moen CSCI/CINF 4230.
Getting a handle on ActionScript A basic primer for non-programmers.
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.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
JavaScript - A Web Script Language Fred Durao
Copyright ©2005  Department of Computer & Information Science Introducing Dialogue Windows.
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Vocabulary in VB So Far. Assignment: Used to change the value of an object at run time Used to change the value of an object at run time.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
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.
JavaScript, Fourth Edition
Event-Driven Programming Chapter Page Section: Section or division of an HTML page Generic block element Example: What's the difference between.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming control structures, events, objects.
IS2802 Introduction to Multimedia Applications for Business Lecture 3: JavaScript and Functions Rob Gleasure
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.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
MIS 3200 – Unit 3.2 Page_Load method AutoPostBack property of controls IsPostBack method of the Page object Understanding web page life cycle.
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.
4. Events are where it happens! Bear Bibeault Yehuda Katz.
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.
H.Melikyan/4910/031 Programming the World Wide Web JavaScript Dr.Hayk Melikyan Departmen of Mathematics and CS JavaScript and HTML Documents.
Event Handling (the right way). A Simple Web Page Events - Summary The web page looks like this:
Host Objects: Browsers and the DOM
Understanding JavaScript and Coding Essentials Lesson 8.
JavaScript Events.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
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.
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.
JavaScript, Third Edition 1 SELECTION LIST Demo. JavaScript, Third Edition 2 Description This web page will edit the slection to ensure an option was.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Third lecture Event 27/2/2016 JavaScript Tutorial.
5.1 JavaScript Execution Environment
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Introduction to JavaScript Events
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and Events.
Chapter 2: GUI API Chapter 2.
13 JavaScript: Events.
Predefined Dialog Boxes
Event Driven Programming & User Defined Functions
Conditionally Confirming a Submit
Unit 6 part 6 Test Javascript Test.
CHAPTER 6 EVENTS. CHAPTER 6 EVENTS WHAT IS AN EVENT?
Presentation transcript:

Dialog boxes in JavaScript Events in JavaScript – What are they – “Which events are there?” – “How do I register event handlers to an HTML element?” – “Once I have successfully accessed the event, how do I read out its properties? ” Topic 5_3: Interacting with the user By the end of this lecture you should :

Topic 5_3: Interacting with the user Dialog boxes: Three methods used by the window object to interact with the user: -alert( ) example 1, example 2example 1example 2 -prompt( ) example 3example 3 -Confirm( ) example 4example 4 Dialog boxes in JavaScript Events in JavaScript What are they “Which events are there?” “How do I register event handlers to an HTML element?” “Once I have successfully accessed the event, how do I read out its properties?

Topic 5_3: Interacting with the user Events – building blocks of interactivity: Object that generates an event (e.g. button) Event handlers supported by the object (e.g. onclick) Custom event handler function may be assigned to the event e.g. function buttonPressed(){//do something} When the user does something an event takes place. An event handler waits until the event takes place and then executes the script you have defined – this is the core of interactivity. - an excellent resource for understanding events in detail Dialog boxes in JavaScript Events in JavaScript What are they “Which events are there?” “How do I register event handlers to an HTML element?” “Once I have successfully accessed the event, how do I read out its properties?

Topic 5_3: Interacting with the user Events: “How should I write an event handling script?” “Which events are there?” ent.asp Dialog boxes in JavaScript Events in JavaScript What are they “Which events are there?” “How do I register event handlers to an HTML element?” “Once I have successfully accessed the event, how do I read out its properties?

Topic 5_3: Interacting with the user Events: “How should I write an event handling script?” “How do I register event handlers to an HTML element?” Traditionally, element.onclick = doSomething; Whenever the user clicks on the HTML element, the function doSomething() is executed. Note that in the registration of an event handler you do not use parentheses () Dialog boxes in JavaScript Events in JavaScript What are they “Which events are there?” “How do I register event handlers to an HTML element?” “Once I have successfully accessed the event, how do I read out its properties?

Topic 5_3: Interacting with the user Events: “How should I write an event handling script?” Dialog boxes in JavaScript Events in JavaScript What are they “Which events are there?” “How do I register event handlers to an HTML element?” “Once I have successfully accessed the event, how do I read out its properties? For example, for a click event can write something like this element.onclick = doSomething; another_element.onclick = doSomething; function doSomething() { this.style.backgroundColor = '#cc0000'; } this always refers to the “owner” of the function we're executing, or rather, to the object that a function is a method of. this always refers to the “owner” of the function we're executing, or rather, to the object that a function is a method of. If we were to execute function doSomething() { this.style.color = '#cc0000'; } without other preparation we would get an error. Why? If we were to execute function doSomething() { this.style.color = '#cc0000'; } without other preparation we would get an error. Why? What else do we need to do to correctly structure code and avoid the error?

Topic 5_3: Interacting with the user Events: “How should I write an event handling script?” A brief note about w3C event handling: -Key method is the addEventListener() -Takes three arguments -Event type -Function to be executed -Boolean value (True or false) To register doSomething() function to the onclick of an element : element.addEventListener('click',doSomething,false) To remove element.removeEventListener('click',doSomething,false) Dialog boxes in JavaScript Events in JavaScript What are they “Which events are there?” “How do I register event handlers to an HTML element?” “Once I have successfully accessed the event, how do I read out its properties?

Topic 5_3: Interacting with the user Events: “How should I write an event handling script?” Using anonymous functions for event handling: For example: element.addEventListener('click',function () { this.style.backgroundColor = '#cc0000' },false) What is the boolean value about? Dialog boxes in JavaScript Events in JavaScript What are they “Which events are there?” “How do I register event handlers to an HTML element?” “Once I have successfully accessed the event, how do I read out its properties?

Topic 5_3: Interacting with the user Events: “How should I write an event handling script?” Event order The boolean value we see in the W3C event listener on the previous slide refers to order of events. Netscape Microsoft W3C Dialog boxes in JavaScript Events in JavaScript What are they “Which events are there?” “How do I register event handlers to an HTML element?” “Once I have successfully accessed the event, how do I read out its properties?

Topic 5_3: Interacting with the user Events: “How should I write an event handling script?” What is the type of the event? Which key is being pressed? Dialog boxes in JavaScript Events in JavaScript What are they “Which events are there?” “How do I register event handlers to an HTML element?” “Once I have successfully accessed the event, how do I read out its properties?