Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.

Slides:



Advertisements
Similar presentations
5.1 JavaScript Execution Environment
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
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.
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 9.
Cos 381 Day 7. © 2006 Pearson Addison-Wesley. All rights reserved. 5-2 Agenda Assignment one graded –Did not see any big issues »Some still have issues.
Computer Science 103 Chapter 4 Advanced JavaScript.
Cos 381 Day 7. © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Agenda Assignment 2 Posted –Program a web-based Version of Soduku using JavaScript.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 10.
CST JavaScript Validating Form Data with JavaScript.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Chapter 5 © 2003 by Addison-Wesley, Inc. 1 Chapter 5 JavaScript and HTML Documents.
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 JavaScript and HTML Documents.
Chapter 5 © 2012 by Addison Wesley Longman, Inc JavaScript Execution Environment - The JavaScript Window object represents the window in which the.
JavaScript Part 1.
CS346 Javascript-7A Events1 DOM Document Object Model and Events.
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.
Using Client-Side Scripts to Enhance Web Applications 1.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
JavaScript - A Web Script Language Fred Durao
Chapter 5 © 2005 by Addison Wesley Longman, Inc JavaScript Execution Environment - The JavaScript Window object represents the window in which the.
DHTML1-1 JavaScript and HTML Documents Xingquan (Hill) Zhu
Chapter 5 © 2014 by Pearson Education JavaScript Execution Environment - The JavaScript Window object represents the window in which the browser.
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.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Chapter 5 © 2010 by Addison Wesley Longman, Inc JavaScript Execution Environment - The JavaScript Window object represents the window in which the.
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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 5. JavaScript and HTML Documents.
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.
Chapter 6 © 2014 by Pearson Education Introduction Def: A dynamic HTML document is one whose tag attributes, tag contents, or element style properties.
CGS 3066: Web Programming and Design Spring 2016 Programming in JavaScript.
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 Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Chapter 6 Dynamic Documents with JavaScript. © 2006 Pearson Addison-Wesley. All rights reserved Introduction Def: A dynamic HTML document is.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Chapter 6 © 2003 by Addison-Wesley, Inc Introduction - Dynamic HTML is not a new markup language - A dynamic HTML document is one whose tag attributes,
6.1 Introduction 6.2 Element Positioning
5.1 JavaScript Execution Environment
JavaScript and HTML Simple Event Handling 11-May-18.
Introduction to JavaScript Events
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
JavaScript and HTML Documents
CHAPTER 7 JavaScripts & HTML Documents
JavaScript and Events CS Programming Languages for Web Applications
5.1 JavaScript Execution Environment
CHAPTER 6 EVENTS. CHAPTER 6 EVENTS WHAT IS AN EVENT?
6.1 Introduction 6.2 Positioning Elements
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and Events CS Programming Languages for Web Applications
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides largest enclosing referencing environment for scripts. – All javaScript variables are properties of some object – The Window properties are visible to all scripts in the document --they are the globals. – Variables created by client-side script become (new) property of Window

Window properties " Property document is a reference to the JavaScript Document object that the window displays " Property frames is an array of references to the (may be multiple) frames of the document " Property forms is an array of references to the forms in the document. – Each Form object has an elements array of references to form's elements.

DOM Document Object Model " Provides specifications for portability for users to write code in programming languages to create documents, work on their structures, change, add, or delete elements and their context " W3c development since early 90's " DOM 0 supported by JavaScript capableborwsers " DOM 1, Oct 98; focused on HTML and XML " DOM 2, Nov 00; support CSS, event, tree manipulation events NS6 but not IE6

DOM " DOM documents have a treelike structure " DOM is abstract model defines interface between HTML documents and application programs " DOM is an OO model -document elements are objects with both data (properties) and operations (methods) " Language supporting DOM must have binding to the constructs

DOM " In JavaScript binding, – HTML elements -->objects – HTML element attributes --> properties would be represented as one object with two properties, type and name, with the values "text" and "address" " For a description of tree traversal, adding and deleting nodes go to in

Element Access in JavaScript " DOM 0 uses forms and element arrays  DOM 0 address: documents.forms[0].element[0]  Element names -- element and all ancestors to have name attributes (but body )  Element name address: documents.myForm.pushMe

Element Access in JavaScript " DOM 1 adrressing via JavaScript method: getElementId – DOM address: document.getElementId("pushme")

Events/Event Handling " HTML 4.0 provided standard --DOM 0 – Supported by all browsers that include JavaScript " DOM 2 comprehensive event model – Supported by Mozilla and NS6 browsers – Not supported by IE6!!

Events/Event Handling " Event-driven: code executed resulting to user or browser action " Event: a notification that soemthing specific occurred -- by browser or user " Event handler: a script implicitly executed in response to event occurrence " Registration: the process of connecting event handler to event

Events/Event Handling JavaScript " Events are JavaScript objects --> names are case sensitive, all use lowercase only. (Method write should never be used in event handler. May cause document to be written over.) " JavaScript events associated with HTML tag attributes which can be used to connect to event- handlers " Table 5.1 (pg 182)

Events/Event Handling JavaScript " One attribute can appear in several different tags: – e.g. onClick can be in and " HTML element get focus: – When user puts mouse cursor over it and presses the left button – When user tabs to the element – By executing the focus method – Element get blurred when another element gets focus " Table 5.2 pg

Event Handling JavaScript " Event handlers can be specified two ways – Assigning the event handler script to an event tag attribute onClick = "alert('Mouse click!');" onClick = "myHandler(); – Assigning them to properties of JavaScript object associated with HTML elements

Event Handling JavaScript " The load event: the completion of loading of a document by browser " The onload attribute of used to specify event handler: " he unload event: used to clean up things before a document is unloaded.

Radio Buttons " The checked property of radio button object is true if the button is pressed " All button in the group have the same name, must use DOM address element var radioElement = document.myForm.elements;

Radio Buttons for ( var inder = 0 ; index < radioElement.length; index++){ if (radioElement[index].checked) { element = radioElement[index].value; break; }

Radio Buttons " Event handlers can be specified by assigning them to properties of JavaScript object associated with HTML elements – Property names are lowercase versions of attribute names – For functions, assign its name to the property: document.myForm.elemnts[0].onClick = myHandler; " Sets handler for first element of array " For radio button group, each element of array must be assigned

Event Handling " Specifying handlers by assigning them to event properties: – Disadvantage --can not use parameters – Advantages: " It is good to keep HTML and JavaScripts separate " Handler could be changed during use

Checking Form Input " JavaScript commonly used to check form input before it is sent to server for processing. – Check for: Format and Completeness " Approach: – Detect error and produce alert messge – Put elemnt in focus (focus function) – Select the element (select function)

Checking Form Input " The focus function puts the element in focus --the cursor in the element document.getElementById("phone").focus(); " The select function highlights the text in the element " After event handler is finished have it return false to keep the form active Neither slect nor focus are supported by NS 6.2

Checking Form Input/Examples " Comparing passwords: – The user is asked to type it twice – Program to very they are the same – The form has two password input boxes to get the passwords, Reset, and Submit buttons – Event handler triggered by Submit – No passwd typed --> focus on box, return false – Two passwds typed-> not same focus and select first box, rerurn false, else return true

Checking Form Input/Examples " Format check for name & tel. Num. – Event handler triggered by change event of text boxes for name and phone number – When error is found, an alert message is produced and both focus and select are called on the textbox element in error – Another event handler will produce a thank you alert when the input is ok.

DOM 2 Model

DOM 2 Event Model " Does not include DOM 0 features, but they are still supported " Much more powerful than DOM 0 " Events propagates – Node of document tree where event is created is the target node – First phase is the capturing phase – Events begin at the root and move toward target node

DOM 2 Event Model " In the capturing phase, if there are any registered handlers at nodes along the way, if one is enabled, then it is run. " The second phase is at the target node. – If there are registered event handlers there for the event, they are run " The third phase is bubbling phase – Event traverses back to the root. All encountered registered handlers are run

DOM 2 Event Model " Not all events bubble " Any handler can stop propagation by calling Event object method stopPropagation " To stop default operations call Event object method preventDefault " Event handler with addEventListerner method – Name of event as literal string, handler function, and boolean value to specify if event is enabled during capturing

DOM 2 Event Model " A temporary handler can be created by registering it and then unregistering it with remove EventListener " The currentTarget property of Events always references the object on which the handler is being executed. " The MouseEvent object (subobject of Event) has two properties: clientX, clientY, the (x,y) coordinates of mouse cursor relative to upper left corner validator2.html

The navigator Object " Indicates which browser is being used. " Two useful properties: – The appName property has the bowser's name – The appVersion has the version number navigator.html