Fluency with Information Technology INFO100 and CSE100 Katherine Deibel 2012-05-09Katherine Deibel, Fluency in Information Technology1.

Slides:



Advertisements
Similar presentations
Tutorial 5 Windows and Frames Section A - Working with Windows.
Advertisements

Sue Wills July Objects The JavaScript language is completely centered around objects, and because of this, it is known as an Object Oriented Programming.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
JQuery CS 380: Web Programming. What is jQuery? jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling,
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Document Object Model (DOM) JavaScript manipulation of the DOM.
HTML 5 and CSS 3, Illustrated Complete Unit L: Programming Web Pages with JavaScript.
Lesson 12- Unit L Programming Web Pages with JavaScript.
The Web Warrior Guide to Web Design Technologies
1 The Information School of the University of Washington Nov 1fit dom © 2006 University of Washington Document Object Model (DOM) INFO/CSE 100, Fall.
Computer Science 103 Chapter 4 Advanced JavaScript.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
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.
CST JavaScript Validating Form Data with JavaScript.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
Chapter 5 Java Script And Forms JavaScript, Third Edition.
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.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
The Document Object Model. Goals Understand how a JavaScript can communicate with the web page in which it “lives.” Understand how to use dot notation.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
UFCEWT-20-3 Advanced Topics in Web Development Lecture 4 : JavaScript, Browsers & the HTML DOM-API.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
D2L Notes Be sure to submit your link in the dropbox provided on D2L You can just upload an empty text file if a file upload is required Do not use D2L.
1 rfXcel Confidential Copyright 2007 Web Technology JavaScript 12/10/07.
JavaScript Programming B.Ramamurthy 6/113/2014B. Ramamurthy CSE6511.
The DOM tree CS The DOM tree CS380 2 Types of DOM nodes  element nodes (HTML tag)  can have children and/or attributes  text nodes (text in.
CITS1231 Web Technologies JavaScript and Document Object Model.
Manipulating the DOM CST 200 – JavaScript 3 –
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
Chapter 5: Windows and Frames
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 10.
Scripting and Interactivity 이병희
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
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.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
Are You Smarter Than a 5 th Grader? 1,000,000 5th Grade HTML 5th Grade Syntax 4th Grade HTML 4th Grade Syntax 3rd Grade HTML 3rd Grade Syntax 2nd Grade.
CO1552 – Web Application Development Further JavaScript: Part 1: The Document Object Model Part 2: Functions and Events.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
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.
HTML DOM Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
JavaScript Document Object Model 1. Document Object Model (DOM) JavaScript access to the elements of an HTML document. An object hierarchy Provides access.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
1 Objects In JavaScript. 2 Types of Object in JavaScript Built-in objects User Defined Objects Browser Object Document Object Model.
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.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
Web Design Principles 5 th Edition Chapter 3 Writing HTML for the Modern Web.
Introduction to.
Programming Web Pages with JavaScript
Applied Component I Unit II Introduction of java-script
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Unit M Programming Web Pages with
HTML & teh internets.
Unit M Programming Web Pages with
The Document Object Model (DOM) is a W3C standard.
Document Object Model That’s DOM to you
Document Object Model (DOM): Objects and Collections
Web Programming and Design
Web Programming and Design
Presentation transcript:

Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1

 The basic idea of arrays  Sometimes you have multiple pieces of data that are related  You do not want to have to make separate variables for each (could be 1000s)  Examples  Calendars  List of elements on a page  Images (multidimensional arrays) Katherine Deibel, Fluency in Information Technology2

 Arrays let you work with multiple values using only one variable name  An index distinguishes each value  Example: Katherine Deibel, Fluency in Information Technology3 stuff (0)"weasels" (1)10 (2) (3)"A cute kitty" (4)true An array called stuff stuff[0] == "weasels" stuff[1] == 10 stuff[2] == etc.

Actually… Objects Katherine Deibel, Fluency in Information Technology4

 What's going on?  What's 'Math.' all about?  Function identifiers cannot use periods!  Why not just random()? Katherine Deibel, Fluency in Information Technology5 Math.random()

 JavaScript is an object-oriented language  What's an object?  For our purposes, an object is a structured collection of related variables and functions  Math is an object pre-built in to JS  Math.random()  Math.sqrt(number);  Math.PI == … Katherine Deibel, Fluency in Information Technology6

 The period is used for accessing the members of an object  General syntax: objectName.memberName  Example: Math.random() looks in the Math object for a function named random Katherine Deibel, Fluency in Information Technology7

 Imagine a bookstore  There are no topic sections  Books are just listed in alphabetical order by title  Could you find a book there?  Yes, but it would be messy Katherine Deibel, Fluency in Information Technology8

 Compartmentalize related code  Examples of built-in objects in JS:  Math  Date  Boolean  Number  String Katherine Deibel, Fluency in Information Technology9

 Objects are more than just a monolithic entity like Math  One can have object variables and we have already been doing that  Example: var x = 4/3; /* object of type Number */ Var y = 5/3; /* object of type Number */ alert("x = " + x.toPrecision(4)); alert("y = " + y.toFixed(2)); Katherine Deibel, Fluency in Information Technology10 x = y = 1.67

 Beyond the scope of this course  CSE 142/143 discuss object-oriented programming in Java  W3Schools:  We will focus on some objects built-in to JavaScript:  String  The Document Object Model Katherine Deibel, Fluency in Information Technology11

Make me a sweater Katherine Deibel, Fluency in Information Technology12

 Strings come with several methods and properties Katherine Deibel, Fluency in Information Technology13

var txt = "Hello!"; alert(txt.length); Katherine Deibel, Fluency in Information Technology14 6

var txt = "Hello!"; alert(txt.length); Katherine Deibel, Fluency in Information Technology15 6

var txt = "Hello123!"; alert(txt.toLowerCase()); alert(txt.toUpperCase()); Katherine Deibel, Fluency in Information Technology16 hello123! HELLO123!

var txt = "Hello123!"; alert(txt.indexOf('H')); alert(txt.indexOf('h')); alert(txt.indexOf('llo')); Katherine Deibel, Fluency in Information Technology17 0 2

Returns a portion of the string var txt = "Hello123!"; alert(txt.subStr(0,2)); alert(txt.subStr(5,3)); alert(txt.subStr(5,4)); alert(txt.subStr(5,20)); Katherine Deibel, Fluency in Information Technology18 He !

Split a string into an array of substrings var txt = "Hello"; alert(txt.split("")); alert(txt.split("l")); alert(txt.split("ll")); txt = " alert(txt.split(".")); Katherine Deibel, Fluency in Information Technology19 H,e,l,l,o He,,o He,o www, uw, edu

On the day of his daughter's wedding, the DOM offers favors Katherine Deibel, Fluency in Information Technology20

 Usually just called the DOM  Some call it the Browser Object Model  Susie thinks such people are silly Katherine Deibel, Fluency in Information Technology21 The BOM? You must be joking!?

 Collection of objects that make up the displayed web page  Interpreted from HTML by browser  Document Object Models are used in most document applications today  Word, Excel, PowerPoint  PDFs  Even some interfaces Katherine Deibel, Fluency in Information Technology22

Katherine Deibel, Fluency in Information Technology23

Katherine Deibel, Fluency in Information Technology24 You should recognize several of these names

Katherine Deibel, Fluency in Information Technology25 body

Katherine Deibel, Fluency in Information Technology26 images

Katherine Deibel, Fluency in Information Technology27 links

Katherine Deibel, Fluency in Information Technology28 forms

Katherine Deibel, Fluency in Information Technology29 What are these? History? Navigator? Location?

 Browser Object Model contains both the DOM and browser elements related to the page  HTML and JS can be used to manipulate the  Page title bar  Navigation bar  Window size  Etc Katherine Deibel, Fluency in Information Technology30 What? I majored in Art, not CS!

 Every element on the page can be accessed and manipulated through the DOM if you know the structure  The structure:  It's all arrays of objects  Actually, it's more like a tree Katherine Deibel, Fluency in Information Technology31

Katherine Deibel, Fluency in Information Technology32

 The tag forms the root  The tag is the trunk  Tags nested within each other form branches off of branches Katherine Deibel, Fluency in Information Technology33

Katherine Deibel, Fluency in Information Technology34 html body h1 pa p headtitle

Not real estate Katherine Deibel, Fluency in Information Technology35

 All forms and images on a page are stored in arrays  document.forms[0]  The first form  document.images[2]  The third image  You can also get the number of such items on the page  document.forms.length  document.images.length Katherine Deibel, Fluency in Information Technology36

 Arrays can be indexed with strings as well as numbers  document.images["bluecar"]  image on page named "bluecar" with the id attribute in HTML.  works since id attributes should be unique in HTML Katherine Deibel, Fluency in Information Technology37

 Most objects in the DOM have the.elements property  Returns an array of all elements (tags) within the specified object Katherine Deibel, Fluency in Information Technology38

 Assume a form has the following tag:  To access that input through the DOM:  Use the input's id: document.forms[0].click. …  Use the.elements property to get an array of each element inside the form: document.forms[0].elements['click']. … Katherine Deibel, Fluency in Information Technology39

 document.forms[0].id1.value Used with text fields to get or set text  document.forms[0].id2.checked Boolean value used with checkboxes and radio buttons to set if input is clicked/selected Katherine Deibel, Fluency in Information Technology40

 document.images[0].src = "…" Get or set the source file for the image  document.images[0].alt = "…" Get or set the alt text for the image  document.images[0].width = # document.images[0].height = # Get or set the dimensions of the image Katherine Deibel, Fluency in Information Technology41

 var tag = getElementById("…")  attach id-attributes to HTML tags and access page elements by this notation, instead of having to wade through the hierarchy  Remember to use unique id s ! Katherine Deibel, Fluency in Information Technology42

 document.getElementsByTagName("p")  Returns an array of all instances of a specific tag on the page  Example: returns all paragraphs on the page  document.getElementsByClassName("…")  Returns an array of all instances of tags that are of a specific class Katherine Deibel, Fluency in Information Technology43

 var p = document.createElement("p"); document.body.appendChild(p);  Allows you to add more nodes to the page  Above code as a paragraph tag to the end of body  p.innerHTML = "Paragraph text"; Sets the text, including tags, in paragraph p Katherine Deibel, Fluency in Information Technology44

 Objects provide further structure to JavaScript and other languages  Learn more about them at W3Schools  Browsers interpret HTML, CSS, JS, etc. to generate the Document Object Model  You can manipulate this through JS  Again, learn more at W3Schools Katherine Deibel, Fluency in Information Technology45