CNIT 133 Interactive Web Pags – JavaScript and AJAX Introduction to JavaScript.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
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.
Java Script Session1 INTRODUCTION.
The Web Warrior Guide to Web Design Technologies
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
JavaScript Programming an Introduction Prepared By P.D. Krolak and M.S. Krolak Based on material from JavaScript Unleashed (2nd Ed)
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
Javascript and the Web Whys and Hows of Javascript.
Introduction to JavaScript Dr. John P. Abraham University of Texas – Pan American.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
UNIT 3 DYNAMIC WEBSITES WITH CSS AND JAVASCRIPT. OBJECTIVES  CO4 Apply style to a website using CSS.  CO5 Describe the use of scripting when creating.
Programming with JavaScript (Chapter 10). XP Various things Midterm grades: Friday Winter Career Fair – Thursday, April 28, 2011 (11 am to 3 pm). – MAC.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
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.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
XP Tutorial 10 Section 1 1 Programming with JavaScript.
1 Server versus Client-Side Programming Server-SideClient-Side.
1 JavaScript in Context. Server-Side Programming.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript and Ajax (JavaScript Basic) Week 2 Web site:
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript and Ajax Week 10 Web site:
1 JavaScript and Dynamic Web Pages Lecture 7. 2 Static vs. Dynamic Pages  A Web page uses HTML tags to identify page content and formatting information.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
Module 1 Introduction to JavaScript
“Under the hood”: Angry Birds Maze
JavaScript is a programming language designed for Web pages.
Web Development & Design Foundations with HTML5 7th Edition
14 A Brief Look at JavaScript and jQuery.
JavaScript Introduction
Objectives Insert a script element Write JavaScript comments
WEB PROGRAMMING JavaScript.
Introduction to JavaScript
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
Presentation transcript:

CNIT 133 Interactive Web Pags – JavaScript and AJAX Introduction to JavaScript

Agenda My Web Site: (download syllabus, class notes). What is JavaScript? JavaScript History JavaScript characteristics Integrating JavaScript into your web documents Objects, Properties, and Methods

What is JavaScript? JavaScript is an interpreted, object-based scripting language modeled after C++. Interpreted languages: an interpreter is needed to translate a program’s statement into machine code. JavaScript Interpreter is built into Web browsers. Object-based language: most of client-side JavaScript’s objects come from Web pages such as images, forms, and form elements. Scripting languages: are easy to learn, easy to use, excellent for small routines and applications, and developed to serve a particular purpose such as PERL, PHP. JavaScript is loosely typed language, which means that variables do not need to have a type specified.

JavaScript History Created by Brendan Eich of Netscape Communications in 1995 as part of Netscape Navigator 2.0. Originally called LiveScript. There are three flavors of JavaScript:  Core JavaScript is the basic JS language include the operators, control structures, built-in functions, and objects that make JS a programming language.  Client-side JavaScript (CSJS): extends the Core JavaScript to provide access to browser and Web document objects via the Document Object Model (DOM).  Server-side JavaScript (SSJS): A Netscape server-side technology. SSJS is embedded directly within HTML documents. HTML documents that contains SSJS must be precompiled into JavaScript byte code. When a Web page that contains SSJS is requested, the server retrieves the document, execute the appropriate byte code on the server, accesses databases and other resources as necessary, and serve up the results as plain vanilla HTML to the browser. ( JavaScript/1/) JavaScript was stabilized and standardized by the European Computer Manufacturer’s Association (ECMA) ( The official name of the language, according to the ECMA-262 standard, is ECMAScript. In practice everyone calls the language JavaScript.

Client-Side JavaScript sample JavaScript sample Client-side JavaScript sample document.write("Hello World! ");

Lexical Structure/Character Set The Lexical Structure of a programming language is the set of elementary rules that specifies how you were program in that language. JavaScript programs are written using the Unicode character set. The 7-bit ASCII encoding is useful only for English. The 8-bit ISO Latin-1 encoding is useful only for English and major Western European languages. The 16-bit Unicode encoding can represent virtually every written language in common use of the planet. The ECMAScript v3 standard allows Unicode characters anywhere in a JavaScript program, version 1 and 2 of the standard allow Unicode characters only in comments and quoted string literals; all elements are restricted to the ASCII character set.

JavaScript is Case Sensitive JavaScript is a case-sensitive language: Document.Write("Hello!");// NOT OK document.write("Hello!");// OK JavaScript ignores “Whitespaces” (spaces, tabs, and newlines) that appear between token in programs. JavaScript automatically inserts semicolons before a line break. var mytext = "abc";// OK var mytext = "abcd efgh ";//NOT OK – a line break inserted into a string JavaScript statements are end with semicolon (;). (optional) Omitting semicolon is not a good programming practice. Single line comment: any text between a // and the end of a line is treated as a comment and is ignored by JavaScript. Multiple lines comment: any text between the characters /* and */ is also treated as a comment.

Literals/Identifiers A literal is a data value that appears directly in a program. 12 //the number twelve (number literal) 1.2 //the number one point two (number literal) "hello world" //a string of text (string literal) 'Hi' //another string (string literal) true //a Boolean value (Boolean literal) null //absence of an object (special value) An identifier is simply a name.  Identifiers are used to name variables and functions, and to provide labels for certain loops in JavaScript code.  Identifier rules The first character must be a letter, an underscore (_). Subsequent characters can be a letter, a digit, an underscore.

The tag When Netscape introduced JavaScript in Netscape 2, it included support for a new tag: the tag. The tag has several attributes, two of which you should always set: language and type. The language attribute specifies which scripting language you are using. language="JavaScript/JavaScript1.1/…" The type attribute specifies the MIME type of the text contained within the tag or the file referenced by the tag. Type="text/javascript" The src attribute: you only need to set this attribute when you attach an external JavaScript file.  An external JS file is just a simple text document with a.js extension.  Only contain JS statements  tags are unnecessary  You may use either a relative or an absolute path to indicate the location of your external JS file

Integrating JS into your web documents In the of an HTML document Inline with HTML as an event handler In an external JavaScript file Inline using the javaScript pseudo-protocol

Placing JS statements in the HTML section Is the perfect place for any statements that need to be read and executed before the contents of your Web document (in the tag) load. Good place to declare user-defined functions (then call it from the area) Good place to declare global variables Should never place statements that “write” Web page content in here.

Placing JS statements in the section This is the best, and only, place to write statements that actually produce content for the inclusion in an HTML document. Calls to functions that declared in the

Custom Greeting Custom Greeting /* Global variable */ var visitor = prompt("What is your name?", ""); Custom Greeting document.write(" Welcome, ", visitor, " ");

Writing JS statements inline as event handlers An event handler is one or more JS statements called in response to a particular event. JS inline as event handler JS inline with event handler

Placing JS statements in an external JS file An external JS file is a simple text file containing only JS statements whose name has a.js extension. Excellent place to declare functions, especially functions you plan to use again and again with a variety of HTML documents. By using an external JS file, you can reduce the overall loading time of your Web site. The external JS file will have to transfer only once, the first time the visitor requests a page that uses it. Any future pages that use that file can access it from the cache, eliminating the need to transfer it again. External JS files also help to hide your code from pilferers. Using an external JS file, you can begin building a library of frequently used functions and routines. Such as formValidation.js

Writing JS statements inline using the JS Pseudo-Protocol You can write JS statements using the javascript: pseudo- protocol in the href attribute of an anchor tag. Instead of going right to a document or resource, the JavaScript pseudo- protocol will execute one or more JS statements, which may or may not return a URL for the anchor to follow. Click me to say HI In the Netscape Navigator browser, typing javascript: into the location bar will cause JS Console to pop up. JS Console displays the latest error messages the browser encountered while executing the scripts. It can be used for light debugging. javascript: var now=new Date(); document.write(" the time is: " + now);

Object Oriented Concepts Object: is an item, thing. It has attributes/properties that describe it. It also has methods which are actions that you can perform with the object or on the object JavaScript uses dot notation to refer to an object and its associated properties and methods. For example, pen is an object To reference ink color property we use the name of the object followed by a dot (period) and the name of the property. pen.inkColor To change the value of an object’s property. Pen.inkColor = "blue"; To reference the object’s method, we reference the name of the object first, followed by a dot and the method name, we end with a set of parentheses. The parentheses are meant to hold any arguments or parameters that provide data to or modify the performance of a method. pen.write("Hello");

Using the write method Using the write method Using the write method document.write("Hello World!!");

Using the write method to write HTML data Using the write method Using the write method to write HTML data document.write(" Hello World!! ");

Changing the background and foreground colors change the background and foreground colors Changing the background and foreground colors document.write(" Hello World!! "); document.bgColor = "blue"; document.fgColor = "white";

The document.write method The document’s write method can accept multiple string parameters separated with commas document.write(string1, string2, …) The following statement would cause an error. You have two choices to fix it: keep the text all on one line or break the string into two strings document.write("long text long text long text long text long text");

Summary of Object Oriented Concepts DescriptionReal-world example JavaScript example ObjectAn item or thing pendocument PropertiesAn attribute that describes an object pen.inkColordocument.bgC olor MethodAn action that can be performed with or on an object pen.write()document.write ()

Where does JS Objects come from Built into the language, like Math, String, Date and Array (Core JS) Come from Web documents and are made available to Client-Side JS via the Document Object Model (DOM) Come from the browser, such as navigator, location, and history objects also made available to Client-Side JavaScript by the DOM Programmers create our own custom objects