June 2008 Florida Atlantic University Department of Computer Science & Engineering ISM 4052 –Internet Application Programming Dr. Roy Levow Session 2.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Chapter 08: Adding Adding Interactivity Interactivity With With Behaviors Behaviors By Bill Bennett Associate Professor MSJC CIS MVC.
JavaScript and AJAX Jonathan Foss University of Warwick
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
Page 1 of 26 Javascript/Jscript Ch 7,8,9,10 Vadim Parizher Computer Science Department California State University, Northridge Spring 2003 Slides from.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
CST JavaScript Validating Form Data with JavaScript.
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.
JavaScript and The Document Object Model MMIS 656 Web Design Technologies Acknowledgements: 1.Notes from David Shrader, NSU GSCIS 2.Some material adapted.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
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.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Database-Driven Web Sites, Second Edition1 Chapter 3 INTRODUCTION TO CLIENT-SIDE SCRIPTS.
1 CLIENT-SIDE SCRIPTS. Objectives 2 Learn how to reference objects in HTML documents using the HTML DOM and dot syntax Learn how to create client-side.
DOM and JavaScript Aryo Pinandito.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
1 rfXcel Confidential Copyright 2007 Web Technology JavaScript 12/10/07.
1 JavaScript: Objects and Object Models October 25, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel,
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Weekend MS CS Program Internet and Web Technologies COT 5930 Web Project Development - Ajax Dr. Roy Levow, Associate Chair & Professor
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Freemarker ● Introduction ● Core features ● Java part example ● Template example ● Expressions ● Builtins ● Assigning value ● Conditions ● Loops ● Macros.
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Scripting and Interactivity 이병희
JavaScript, Fourth Edition
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Introduction To JavaScript. Putting it Together (page 11) All javascript must go in-between the script tags. All javascript must go in-between the script.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 4 JavaScript.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
JavaScript.
14 A Brief Look at JavaScript and jQuery.
Web Systems Development (CSC-215)
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Presentation transcript:

June 2008 Florida Atlantic University Department of Computer Science & Engineering ISM 4052 –Internet Application Programming Dr. Roy Levow Session 2

Internet Application Programming, June Lesson Plan – Session 2 Client-Side Programming JavaScript Literals, Variables, Expressions, Control Statements, Functions, Arrays, Objects Document Object Model (DOM) Objects and Collections JavaScript Events Event & Handlers Introduction to AJAX XMLHttpRequest Google Maps API

Internet Application Programming, June JavaScript Programming language with some object- oriented features Interpreted from source code Supported by most browsers Executed on client system in browser Program text output is treated as HTML and rendered by browser Includes extensive support for generating web page and window elements

Internet Application Programming, June Variables and Assignment Variable names essentially as in C++ No type in declaration var name1, name2, …; Type depends on value and can change on assignment of new value Assignment operator =

Internet Application Programming, June Expressions Very similar to C++ Arithmetic Operators: + - * / % etc. as in C++ Comparison operators: … If one operand is a string and the other a number, comparison is numeric by converting string Use === and !== for strict comparison No conversion; “5” === 5 -> false String concatenation with + Concatenation with string converts other values to string if possible

Internet Application Programming, June Output with document.writeln( str ); or document.write Simple input with val = window.prompt(“msg”); Simple I/O

Internet Application Programming, June Basic Control Structures Like C/C++ if (cond) stmt else // optional else part stmt { … } // block while (cond) stmt for (init; test; incr) stmt

Internet Application Programming, June Use on Web Page Code in body Executed when encountered Output becomes part of page HTML at that place Functions and initializations can go in head Init code output goes at top of body

Internet Application Programming, June Wrap each code segment with <!-- // code goes here --> Comment avoids problems is browse doesn’t recognize scripts Use on Web Page (2)

Internet Application Programming, June Examples Class Average 2 (Ex. 7.9) Sentinel for end of input Analysis (Ex. 7.11) Interest Table (Ex. 8.6) Observe that tags and other HTML must be written by script

Internet Application Programming, June More Control Statements switch (choice) { case val: stmt break; … default: // optional stmt } do stmt while (cond); break and continue as in C/C++

Internet Application Programming, June Examples Bullet lists with switch (Ex. 8.7) Headings with do-while (Ex. 8.9)

Internet Application Programming, June Logical Values and Operators Logical Values are truefalse Can’t use 0, not 0 as in C Usual logical operators !&&|| Short-circuit evaluation

Internet Application Programming, June Defining Functions function fname(parm1, parm2, …) { //code return expr; } Notes No return type expr in return omitted if no return value

Internet Application Programming, June Example Table of Random Numbers, Ex. 9.4 Note use of functions from class Math Die Roll Simulation (Ex. 9.5) Craps Game (Ex. 9.6)

Internet Application Programming, June Arrays Array is a class Declare array with var list = new Array(size); Access with list[index]; Start index with 0 Can hold any type of value Deallocation is automatic when another value is assigned to variable list.length returns length of array

Internet Application Programming, June Arrays Initialization In constructor new Array(“red”, “green”, “blue”); By array object x = [1, 2, 3, 4]; Can have undefined values; never assigned Example: DieRoll with array, Ex. 10.6

Internet Application Programming, June Reference Parameters Arrays and objects are passed by reference so a change of value in the function changes the calling value Scalars are passed by value

Internet Application Programming, June Two-dimensional Arrays Declare an Array for rows Then assign an Array to each element Does not enforce rectangular form Access with Array[i][j] In for statement can use for (var j in theArray[i]) instead of counting

Internet Application Programming, June Objects Use similar to C++ or Java Declared with new Components accessed with dot notation Math object has elements that are standard mathematical functions Math.sin(x), Math.max(x, y), Math.sqrt(x), etc.

Internet Application Programming, June Strings Class String supports character strings Constants are surrounded by “ “ Can use usual C++ \ escapes Has many methods for string manipulation Operator + for concatenation Examples: String methods, Ex Split and substring, Ex 11.6

Internet Application Programming, June Date Object Access and format date and time See definitions at W3Schools Example: DateTime.html fig. 12.9fig. 12.9

Internet Application Programming, June Document and Window Objects Document object allows access to all components of a document See definitions at W3Schools Window object allows control of window features See definitions at W3Schools Example: Window.html, Ex

Internet Application Programming, June Cookies Accessed through Document cookie property Example: cookie.html, Ex Quiz Example Ex , 11.17

Internet Application Programming, June From Session 1, Slides 23 & 24 XHTML Forms

Internet Application Programming, June Dynamic Object Model (DOM) Tree structure represents elements of document XHTML XHTML elements accessed as objects Navigate and manipulate tree XHTML attributes become properties of the objects The properties can be manipulated by scripts for dynamic effect The id attribute permits direct access by name

Internet Application Programming, June Tools to view DOM tree Firefox – DOM Inspector IE7 – Developer Toolbar Accessing nodes in DOM tree with JavaScript Access, Insert, Delete, Replace, Remove, Get Parent Ex Viewing and Manipulating DOM Tree

Internet Application Programming, June DOM Collections A collection is basically an array of related objects Many collections; defined by node type ‘all’ collection consists of all XHTML elements of a document ‘children’ collection of an object consists of all the immediately contained elements links, anchors, images, forms Ex. 12.3

Internet Application Programming, June Dynamic Styles Styles can change dynamically Any style element can be changed Refer to DOM_element.style.style_attrib Ex. 12.4

Internet Application Programming, June XHTML tags can contain an event attribute with a call to a function to execute when that event is triggered on the item Event handlers can also be registered through DOM manipulation Sample events: onclick, onmouseover, onload Ex. 13.1, 13.2, 13.3 JavaScript Events

Internet Application Programming, June Rollovers mouseover, mouseout Ex Form processing with onfocus and onblur Ex Form processing with onsubmit and onreset Ex Event bubbling, Ex Events (2)

Internet Application Programming, June Ajax Asynchronous JavaScript And XML Provides a framework for the development of web pages that are Interactive Highly dynamic Small transfers that update current page provide faster, smoother response

Internet Application Programming, June Ajax Site Example Google Suggest Google Maps Gmail Google Page Creator Google Docs (Web substitute for MS Office)

Internet Application Programming, June Ajax vs. Classic Page Loads

Internet Application Programming, June Classic Synchronous Loads

Internet Application Programming, June Ajax Asynchronous Loads

Internet Application Programming, June AJAX uses XMLHttpRequest to fetch data for page updates Coding data as XML is normative but not essential Ex Key Elements XMLHttpRequest object properties & methods Callback Functions Exception Handling Full development requires server-side program Simple AJAX Interaction

Internet Application Programming, June Programming interface to incorporate Google maps into web pages Maplet = maps + gadgets Free registration required Uses built-in AJAX for map updates Google Maps API

Internet Application Programming, June Basic Map Objects Map Events Map Controls Map Overlays Map Services Google Maps Concepts

Internet Application Programming, June Choose one of the following Customizable web page Simple calculator Sudoku player XHTML DOM Project Maplet Project Develop a web application that incorporates a Maplet Use a from to collect data to manipulate map