CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.

Slides:



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

Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
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.
Georgia Institute of Technology JavaScript part 2 Barb Ericson Georgia Institute of Technology May 2006.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
JavaScript Forms Form Validation Cookies CGI Programs.
20-Jun-15 JavaScript and HTML Simple Event Handling.
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.
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
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.,
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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript forms.
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.
JavaScript - a Brief Introduction Anupriya. What is JavaScript Object based (not object oriented) programming language –very limited object creation –a.
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
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
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.
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.
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
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
44238: Dynamic Web-site Development Client Side Programming Ian Perry Room:C48 Extension:7287
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.
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.
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.
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 
Web Programming Java Script & jQuery Web Programming.
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.
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.
Understanding JavaScript and Coding Essentials Lesson 8.
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.
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.
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.
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Copyright © Terry Felke-Morris Web Development & Design Foundations with HTML5 8 th Edition CHAPTER 14 KEY CONCEPTS 1 Copyright.
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.
JavaScript and HTML Simple Event Handling 19-Sep-18.
JavaScript Events.
Functions, Regular expressions and Events
JavaScript and Ajax (JavaScript Events)
CNIT 133 Interactive Web Pags – JavaScript and AJAX
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling

Agenda My Web Site: (download syllabus, class notes). Event and Event handling. Event samples.

Event and Event Handler Defined Events: are visitor and browser activities. (the phone rings) Event handlers: are the mechanisms that allow us to capture and actually respond to those events with a scripting language. (pick up the phone and say, “Hello”)

Writing Event Handlers Event handlers: are written inline with HTML, just like an HTML attribute. Therefore, Event handlers also called intrinsic event attributes. (the only different is that Event Handler executes JS script or function). HTML Tag: Event handler/intrinsic event attribute:

Events and Event Handling JavaScript programs use an event-driven programming model. The web browser generates an event whenever something interesting happens to the document or to some element of it. For example, the web browser generates an event when it finishes loading a document, when the user moves the mouse over a hyperlink, or when the user clicks on a button in a form If a JavaScript application cares about a particular type of event for a particular document element, it can register an event handler – a JavaScript function or snippet of code – for that type of event on the element of interest. Then, when the particular event occurs, the browser invokes the handler code. All application with graphical user interfaces are designed this way: they sit around waiting for the user to do something interesting (i.e. they wait for events to occur), and then they respond.

Events and Event Handling Three distinct and incompatible event- handling models are in used:  The original event model  The standard event model  The Internet Explorer event model

Basic Event Handling In the original event model, event-handling code is specified using the attributes of HTML elements. Thus, if your application needs to know when the user moves the mouse over a specific hyperlink, you use the onmouseover attribute of the tag that defines the hyperlink. If the application needs to know when the user clicks the Submit button, you use the onClick attribute of the tag that defines the button or the onsubmit attribute of the element that contains that button.

Basic Event Handling There are quite a few different event-handler attributes that you can use in the original event model. They are :  onblur  onchange  onclick  onfocus  onkeydown  onkeypress  onkeyup  onload  onmousedown  onmousemove  onmouseout  onmouseover  onmouseup  onsubmit  onunload

Event Handler Return Values In many cases, an event handler uses its return value to indicate the disposition of the event. For example, if you use the onsubmit event handler of a Form object to perform form validation and discover that the user has not filled in all the fields, you can return false from the handler to prevent the form from actually being submitted: <form action = "search.cgi" onsubmit="if (this.elements[0].value.length == 0) return false; ">

Event Handlers and the this Keyword When your event handler is invoked, it is invoked as a method of the element on which the event occurred, so the this keyword refers to that target element: // the this keyword refers to the Button object.

The Pseudo-protocol & the void operator The pseudo-protocol (javascript:) in the href attribute of an or tag: the idea is that instead of requesting a document, the JS pseudo-protocol will instead execute one or more JS statements, which may or may not return a URL to the href. The void operator: tells the interpreter to evaluate an expression and return no value.  void (expression) or void expression  NOTE: void is an operator, not a function, where expression is an expression to be evaluated. Parentheses are optional. You want to make certain that a statement called via the pseudo-protocol does not return a value and provoke the link to load a new document indicated by the returned value. The void operator will ensure that no value is returned to the hypertext link at all.

Intrinsic Event Attributes EventIntrinsic Event Attribute LoadonLoad (associated with windows, images) UnloadonUnload (associated only with windows) ClickonClick (associated with any elements) MouseOveronMouseOver (associated with any elements) MouseOutonMouseOut (associated with any elements) FocusonFocus (associated with windows, frames, links, and form elements) BluronBlur (associated with windows, frames, links, and form elements) SubmitonSubmit (associated with forms) ResetonReset (associated with forms) SelectonSelect (associated with text boxes, password, text areas) ChangeonChange (associated with text boxes, text areas, password, file uploads, select lists)

Event – onload sample function mymessage() { alert("This message was triggered from the onload event"); }

Event – onunload sample function mymessage() { alert("This message was triggered from the onunload event"); } An alert box will display a message when you close this document!

Event – onchange sample function preferedBrowser() { prefer=document.forms[0].browsers.value; alert("You prefer browsing internet with " + prefer); } Choose which browser you prefer: Internet Explorer Netscape

Event – onsubmit sample function confirmInput() { fname=document.forms[0].fname.value; alert("Hello " + fname + "! You will now be redirected to } Enter your name:

Event – onblur sample function message() { alert("This alert box was triggered by the onblur event handler"); } The onblur event occurs when an element loses focus. Try to click or write in the input field below, then click elsewhere in the document so the input field loses focus. Enter your name:

Event – onfocus sample function message() { alert("This alert box was triggered by the onfocus event handler"); } Enter your name:

Event – onmouseover & onmouseout sample <h1 onmouseover="style.color='red'" onmouseout="style.color='black'"> Mouse over this text

Event – onclick sample function disp_func() { Alert(“This alert box was triggered by the onclick event handler”); }

Event – onmousemove sample var i=1; function moveright() { document.getElementById('header').style.position="relative"; document.getElementById('header').style.left=i; i++; } Move the mouse over this page

In-class sample 0 Events function callHandler(str) { } Event and Event Handler Move the mouse to this text and see. Then move the mouse out of the text and see!! Click Here Text Box:

In-class sample 1 Events function callHandler(str) { alert(str); } Event and Event Handler Move the mouse to this text and see. Then move the mouse out of the text and see!! Click Here <!-- or use this format Click Here --> <form action="" method="post" onSubmit="callHandler('Form submitted! Thank you!')" onReset="callHandler('Reset event'); return confirm('Are you sure to reset?')"> Text Box: <input type="text" onFocus="callHandler('Focus to text box')" onBlur="callHandler('Text box lost focus')" onChange="call Handler('Text box changes data!')" onSelect="callHandler('Selected some text in text box')">