Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I HTML DOM part II Jongwook.

Slides:



Advertisements
Similar presentations
5.1 JavaScript Execution Environment
Advertisements

JavaScript and AJAX Jonathan Foss University of Warwick
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
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.
Lesson 12- Unit L Programming Web Pages with JavaScript.
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.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
JavaScript Forms Form Validation Cookies CGI Programs.
Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I JQuery Part II Jongwook.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 9.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
AJAX (Asynchronous JavaScript and XML) Amit Jain CS 590 – Winter 2008.
Computer Science 103 Chapter 4 Advanced JavaScript.
Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I Javascript Jongwook Woo,
Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I JQuery Part I Jongwook Woo,
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 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.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 JavaScript and HTML Documents.
JavaScript & DOM Client-side scripting. JavaScript JavaScript is a tool to automate client side (which is implemented using HTML so far) JavaSript syntax.
UFCEWT-20-3 Advanced Topics in Web Development Lecture 4 : JavaScript, Browsers & the HTML DOM-API.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
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.
History, Navigator, Screen and Form Objects Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
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.
An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
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.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
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 -
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.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 5. JavaScript and HTML Documents.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
HTML DOM Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
JavaScript محمد احمدی نیا 2 Of 48 What is JavaScript?  JavaScript was designed to add interactivity to HTML pages  A scripting.
Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I HTML DOM part I Jongwook.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
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 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.
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.
COM621: Advanced Interactive Web Development Lecture 6 – JavaScript (cont.)
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
SE-2840 Dr. Mark L. Hornick 1 Dynamic HTML Handling events from DOM objects.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Scripting the DOM MIS 3502, Fall 2016 Jeremy Shafer Department of MIS
Applied Online Programming
Web Development & Design Foundations with HTML5 7th Edition
JavaScript and HTML Documents
CHAPTER 7 JavaScripts & HTML Documents
Document Object Model (DOM): Objects and Collections
Presentation transcript:

Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I HTML DOM part II Jongwook Woo, PhD California State University, Los Angeles Computer Information System Department

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System Content nDOM Node Access nDOM Events

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System DOM Node Access (Cont’d) nYou can access a node in three ways: mBy using the getElementById() method mBy using the getElementsByTagName() method mBy navigating the node tree, using the node relationships nThe getElementById() Method mreturns the element with the specified ID: mSyntax –node.getElementById("id"); mExample –document.getElementById("intro"); The example gets the element with id="intro":

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System DOM Node Access (Cont’d) getElementsByTagName() Method nThe getElementsByTagName() Method mreturns all elements with a specified tag name. nSyntax mnode.getElementsByTagName("tagname"); nExample 1 mdocument.getElementsByTagName("p"); –The example returns a nodeList of all elements in the document: nExample 2 mdocument.getElementById('main').getElementsByTagName ("p"); –The example returns a nodeList of all elements that are descendants of the element with id="main":

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System DOM Node Access (Cont’d) getElementsByTagName() Method nreturns a node-list. mThat is, elements mA node-list is an array of nodes nExample mx=document.getElementsByTagName("p"); –The code selects all nodes in a node-list: –The nodes can be accessed by index number. To access the second you can write: –y=x[1]; Note: The index starts at 0.

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System DOM Node Access (Cont’d) getElementsByTagName() Method Hello World! The DOM is very useful! x=document.getElementsByTagName("p"); document.write("Text of second paragraph: " + x[1].innerHTML); nDisplay “The DOM is very useful!” nFor x[0].innerHTML mDisplay “Hello World!” nFor x[2].innerHTML mDisplay Nothing – out of bounce error

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System DOM Node Access (Cont’d) getElementsByTagName() Method nDOM Node List Length mThe length property defines the number of nodes in a node-list. mYou can loop through a node-list by using the length property: nExample x=document.getElementsByTagName("p"); for (i=0;i "); } mGet all element nodes –For each element, output the value of its text node –For the previous slides: x.length: 2 x[0].innerHTML: Hello World! x[1].innerHTML: The DOM is very useful!

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System DOM Node Access Navigating Node Relationships nWith parentNode, firstChild, and lastChild m Hello World! The DOM is very useful! This example demonstrates node relationships. mFor the “body” element, –the first p element is the first child node (firstChild) –the div element is the last child node (lastChild) –The parent node (parentNode) of the first p element and the div element mFor the “div” element –the parent node of the p elements inside the div element

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System DOM Node Access Navigating Node Relationships (Cont’d) nto access the text of an element: mThe firstChild property can also be used nExample m Hello World! x=document.getElementById("intro"); document.write(x.firstChild.nodeValue);

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System DOM Node Access Navigating Node Relationships (Cont’d) nDOM Root Nodes mdocument.documentElement –returns the root node of the document mdocument.body –gives direct access to the tag

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System DOM Events nEvents mEvents are actions that can be detected by JavaScript. mEvery element on a web page has certain events –which can trigger JavaScript functions. nExamples of events: mA mouse click mA web page or an image loading mMousing over a hot spot on the web page mSelecting an input box in an HTML form mSubmitting an HTML form mA keystroke

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System onload and onUnload Events ntriggered when the user enters or leaves a page. nThe onload event moften used to check the visitor's browser type and version, –load the proper version of the web page based on that information. nBoth the onload and onUnload events moften used to deal with cookies that should be set when a user enters or leaves a page. mFor example, you could have a popup to display an alert after loading a page

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System Onload Event nAlert "Page is loaded" mimmediately after a page is loaded: function load() { alert("Page is loaded"); } Hello World!

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System onChange Events noften used in combination with validation of form fields. nExample mThe check () function will be called –whenever the user changes the content of the field:

Jongwook Woo CSULA Jongwook Woo Computer Information System Information System onChange Events nexample when a user changes the content of an input field: mhttp:// mThe toUpperCase() method of Javascript converts a string to uppercase letters ( –string.toUpperCase() function upperCase(x) { var y=document.getElementById(x).value; //input document.getElementById(x).value=y.toUpperCase(); //output } Enter your name: