INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, February 19, 2014 Session 4: JavaScript.

Slides:



Advertisements
Similar presentations
Working with Forms. how are forms manipulated? the document object contains an array of forms objects, one for each form, in document order –forms[] any.
Advertisements

INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, September 19, 2013 Session 3: JavaScript.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
The Document Object Model (DOM) 1 JavaScript is an object-based language—that is, it’s based on manipulating objects by changing each object’s properties.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Page Elements © Copyright 2014, Fred McClurg All Rights Reserved.
Document Object Model (DOM) JavaScript manipulation of the DOM.
Tutorial 16 Working with Dynamic Content and Styles.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
LBSC 690 Session #10 Programming, JavaScript Jimmy Lin The iSchool University of Maryland Wednesday, November 5, 2008 This work is licensed under a Creative.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Tutorial 13 Working with Objects and Styles. XP Objectives Learn about objects and the document object model Reference documents objects by ID, name,
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
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.
JS: Document Object Model (DOM)
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
JavaScript & DOM Client-side scripting. JavaScript JavaScript is a tool to automate client side (which is implemented using HTML so far) JavaSript syntax.
JavaScript Lecture 6 Rachel A Ober
UFCEWT-20-3 Advanced Topics in Web Development Lecture 4 : JavaScript, Browsers & the HTML DOM-API.
DOM and JavaScript Aryo Pinandito.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
JavaScript – The DOM JavaScript is object based The browser is object based – We can access the browser's objects in the same way we did JavaScript's Two.
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
5.2 DOM (Document Object Model). 2 Motto: To write it, it took three months; to conceive it three minutes; to collect the data in it — all my life. —F.
Using Client-Side Scripts to Enhance Web Applications 1.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
XP Tutorial 16 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Dynamic Content and Styles Creating a Dynamic Table of Contents.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Set 2: DOM IT452 Advanced Web and Internet Systems.
Advanced DOM Builds on last presentation on DOM Allows you to dynamically create elements and position them on a page DOM methods/properties are W3C standard.
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.
CO1552 – Web Application Development Further JavaScript: Part 1: The Document Object Model Part 2: Functions and Events.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 9, 2014 Session 5: JavaScript.
DOM (Document Object Model) - Parsing and Reading HTML and XML -
Lesson 16. Practical Application 1 We can take advantage of JavaScript and the DOM, to set up a form so that the first text box of a form automatically.
Advanced DOM Builds on last presentation on DOM Allows you to dynamically create elements and position them on a page DOM methods/properties are W3C standard.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 9.
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Making web pages interactive with JavaScript.
CSE 154 LECTURE 9: THE DOM TREE. The DOM tree The elements of a page are nested into a tree-like structure of objects the DOM has properties and methods.
XML DOM Week 11 Web site:
DOM Dr. Reda Salama. Back to the HTML DOM Once we get a response back from the server, we probably want to update our HTML page The HTML page itself is.
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.
Introduction to JavaScript DOM Instructor: Sergey Goldman.
XP Tutorial 10 New Perspectives on JavaScript, Comprehensive 1 Working with Dynamic Content and Styles Creating a Dynamic Table of Contents.
Tarik Booker CS 120 California State University, Los Angeles.
THE DOM.
Programming Web Pages with JavaScript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Unit M Programming Web Pages with
Scripting the DOM MIS 3502, Fall 2016 Jeremy Shafer Department of MIS
CGS 3066: Web Programming and Design Spring 2017
Introduction to JavaScript Events
CGS 3066: Web Programming and Design Spring 2016
JavaScript Functions.
Document Object Model (DOM): Objects and Collections
© 2015, Mike Murach & Associates, Inc.
Document Object Model (DOM): Objects and Collections
JavaScript and the DOM MIS 2402 Jeremy Shafer Department of MIS
Web Programming and Design
JavaScript and the DOM MIS 2402 Maxwell Furman Department of MIS
Presentation transcript:

INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, February 19, 2014 Session 4: JavaScript – DOM and Events

Source: Iron Chef America Programming… is a lot like cooking!

Arrays An array holds a collection of values Each value is referenced with an index, starting from 0 Creating an array: Or, alternatively: Note, arrays automatically grow in size var arr = new Array(); arr[0] = 0; arr[1] = 3; arr[2] = 2; arr[3] = 4; var arr = [0, 3, 2, 4]; What happens if you don’t specify value for a particular index?

Using Arrays Referencing values in an array: Array values can be used in other expressions and statements: var f = 5 + arr[0] + arr[2]; Find out the length of an array: arr.length Arrays and for loops go hand in glove: arr[0] name of arrayindex (starts at 0!) var arr = [0, 3, 2, 4]; var sum = 0; for (var i=0; i<arr.length; i++) { sum += arr[i]; } console.log(sum);

Cooking analogy? Source:

The Document Object Model (DOM) Source:

The Document Object Model (DOM) Source:

document Source: headbody h1ppul li

Asking the DOM to “do stuff” document.method(“argument”); document represents the entire page and contains the DOM the method is want you want the document “to do”, usually a verb phrase arguments are additional details that you specify More on the dot notation later…

DOM: Selecting Nodes Selecting a DOM node by id: document.getElementById("id"); Note, returns a DOM node Selecting DOM nodes by tag: document.getElementsByTagName("p"); Note, returns a collection (treat as an array) Once you select a DOM node: Get a node’s children: list.childNodes Get a node’s number of children: list.childNodes.length Natural to iterate over child nodes using for loops BTW, tags are very useful for grouping elements together.

DOM: Manipulating Nodes Simplest way to manipulate DOM nodes: select the node and modifying its innerHTML property: var p = document.getElementById("para"); p.innerHTML = "some text"; innerHTML can be any HTML! Modify a child node using innerHTML: document.getElementById("list").childNodes[1].innerHTML = "new item";

DOM: Building Nodes Building DOM nodes programmatically: var p = document.createElement("p"); p.innerHTML = "here is some new text."; document.getElementById("div1").appendChild(p); var newItem = document.createElement("li"); newItem.innerHTML = "new list item"; document.getElementById("list").appendChild(newItem); Set setAttribute method to set attributes document.getElementById("para").setAttribute("style", "font-family: arial");

DOM: Removing Nodes Select the node to remove, then use the removeChild method in its parent: var list = document.getElementById("list"); var listItem = list.childNodes[1]; list.removeChild(listItem);

Let’s build a table! Source: Wikipedia (Table)

var t = document.createElement("table"); t.setAttribute("border", 1); var row1 = document.createElement("tr"); var row1col1 = document.createElement("td"); row1col1.innerHTML = "A"; var row1col2 = document.createElement("td"); row1col2.innerHTML = "B"; row1.appendChild(row1col1); row1.appendChild(row1col2); t.appendChild(row1); document.getElementById("div1").appendChild(t);

Events GUI are driven by events When an event happens, an event handler is called to “handle” the event Easier to show in an example… Note, what I’m showing is slightly easier than what’s in the book…

Source: Wikipedia (Form (Document)) Forms

Source: Wikipedia (Construction) Putting everything together…