Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.

Slides:



Advertisements
Similar presentations
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Advertisements

Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
20-Jun-15 JavaScript and HTML Simple Event Handling.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
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.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
INTRODUCTION TO DHTML. TOPICS TO BE DISCUSSED……….  Introduction Introduction  UsesUses  ComponentsComponents  Difference between HTML and DHTMLDifference.
JavaScript and The Document Object Model MMIS 656 Web Design Technologies Acknowledgements: 1.Notes from David Shrader, NSU GSCIS 2.Some material adapted.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
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.
1 JavaScript: Event Model November 1, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg.
DOM and JavaScript Aryo Pinandito.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
Creating an Animated Web Page
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.
An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
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.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 10.
Chapter 14: Dynamic HTML: Event Model Presented by: Colbie Brown CS340 Java Web Development Dr. Gloria Carter Love.
1 Dr Alexiei Dingli XML Technologies SAX and DOM.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
 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.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
Rich Internet Applications 3. Client JavaScript. Document Object Model (DOM) The DOM, is an interface that allows scripts or programs to access and manipulate.
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.
DOM (Document Object Model) - Parsing and Reading HTML and XML -
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
Host Objects: Browsers and the DOM
Document Object Model (DOM). Outline  Introduction of DOM  Overview of DOM  DOM Relationships  Standard DOM.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
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.
Document Object Model.  The XML DOM (Document Object Model) defines a standard way for accessing and manipulating XML documents.  The DOM presents an.
JQUERY AND AJAX
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
XML DOM Week 11 Web site:
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
Copyright © Terry Felke-Morris Web Development & Design Foundations with HTML5 8 th Edition CHAPTER 14 KEY CONCEPTS 1 Copyright.
CIS 375—Web App Dev II DHTML. 2 Introduction to DHTML _________ HTML is “a term used by some vendors to describe the combination of HTML, style sheets.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
THE DOM.
Introduction to.
DHTML.
JavaScript and HTML Simple Event Handling 11-May-18.
Unit M Programming Web Pages with
Week 4: Introduction to Javascript
Web Development & Design Foundations with HTML5 7th Edition
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and HTML Simple Event Handling 19-Sep-18.
Week 11 Web site: XML DOM Week 11 Web site:
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
CHAPTER 7 JavaScripts & HTML Documents
© 2015, Mike Murach & Associates, Inc.
Web Design and Development
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Javascript II DOM & JSON

In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers directly. But…initially each browser developed its own Application Programming Interface (API) and they were not compatible making cross-browser development problematic. W3C helped gain a consensus on a common API for dynamically accessing and updating web documents

The Document Object Model “The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.” Applies to HTML, as well as XML Defines the objects and their properties, and the methods to access them. Most recent “level” is DOM Level 3 (2004)

Document as a node tree My title My link My header

Parent, Child, Sibling

Programming Interface of DOM Defines standard properties and methods –Properties are attributes of an object, such as the name of a node. –Methods are things that can be done, such as removing a node Methods are used to get objects or their properties Methods are used to modify objects (i.e., insert a node) and their properties (i.e., change a node’s ID)

Some HTML DOM Properties x.innerHTML - the text value of x x.nodeName - the name of x x.nodeValue - the value of x x.parentNode - the parent node of x x.childNodes - the child nodes of x x.attributes - the attributes nodes of x txt=document.getElementById("intro").innerHTML;

Some HTML DOM Methods x.getElementById(id) - get the element with a specified id x.getElementsByTagName(name) - get all elements with a specified tag name x.appendChild(node) - insert a child node to x x.removeChild(node) - remove a child node from x

Events An event handler executes code when an event (an action detected by JavaScript such as a mouse click, page load, keystroke, etc.) occurs. <input type="button" onclick="document.body.style.backgroundColor='lavender';" value="Change background color" />

Event Attribute examples Onblur - an element loses focus Onclick - mouse clicks an object Onerror - an error occurs when loading a document or image Onload - a pge or image is finished loading Onmouseover - the mouse is moved over an element Onunload - the user exits the page

Form Validation Example Old-school examples (still common) –SyntaxSyntax –Example pageExample page The code –More complex form exampleexample The code HTML5 exampleexample There are also many Javascript libraries that simplify form validation

More DOM Examples A list of examples that use the DOM: A reference of built-in JavaScript objects, browser objects, and HTML DOM objects. Use this to see what is possible:

JavaScript Object Notation (JSON) “syntax for storing and exchanging text information” Similar to XML, but faster and easier to parse - particularly using JavaScript eval() or a JSON parser (which is more secure) Language and platform independent

JSON & JavaScript

JSON Example & Exercise Go to ename=tryjson_create ename=tryjson_create Modify it so that it includes an address line

Additional Resources W3schools.com Douglas Crockford’s JavaScript videos and other resources on DOM and JSON: (note: he “discovered”/invented JSON)