CP476 Internet Computing JavaScript Client-Side Programming 1 1. What is JavaScript –Another script language for both client-side and sever-side programming.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Introducing JavaScript
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Java Script Session1 INTRODUCTION.
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
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
Tutorial 10 Programming with JavaScript
Chapter 6 © 2002 by Addison Wesley Longman, Inc. 1 Chapter 6 Sebesta: Programming the World Wide Web.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to scripting
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Scripting Languages.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Chapter 4 © 2003 by Addison-Wesley, Inc Overview of JavaScript - Originally developed by Netscape, as LiveScript - Became a joint venture of Netscape.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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.
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.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Lecture 9 The Basics of JavaScript Boriana Koleva Room: C54
1 Overview JavaScript (Recommended Reading : Programming the World Wide Web, 4 th Edition, Robert W. Sebesta, Chapters 4, 5 – available at Steely Library)
JavaScript - A Web Script Language Fred Durao
1 Introduction to Web Application Introduction to Java Script.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript Syntax, how to use it in a HTML document
Introduction to JavaScript CS101 Introduction to Computing.
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.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
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.
JS1-1 Introduction to JavaScript (JavaScript 1) Xingquan (Hill) Zhu
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 JavaScript in Context. Server-Side Programming.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
REEM ALMOTIRI Information Technology Department Majmaah University.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
PHP using MySQL Database for Web Development (part II)
4.1 Overview of JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
JavaScript is a programming language designed for Web pages.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript and Ajax (Expression and Operators)
WEB PROGRAMMING JavaScript.
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript: Introduction to Scripting
Presentation transcript:

CP476 Internet Computing JavaScript Client-Side Programming 1 1. What is JavaScript –Another script language for both client-side and sever-side programming –Originally developed by Netscape as LiveScript 1995, then jointed with Sun Microsystems, and renamed it to JavaScript – Three categories of JavaScript Core, the base JavaScript language client-side, extended version for web pages server-side, extended version for server side file and database access –JavaScript and Java are only related through syntax JavaScript is dynamically typed JavaScript has limitted support for OOP –JavaScript can be embedded in many different things, but its primary use is embedded in HTML documents Lecture 16. JavaScript Objective: to learn how to pass computation to client side by embedding JavaScript code into HTML.

CP476 Internet Computing JavaScript Client-Side Programming 2 –JavaScript can be used to replace some of what is done with CGI (but no file operations or networking) User interactions with forms The Document Object Model makes it possible to support dynamic HTML documents with JavaScript –Event-Driven Computation User interactions with HTML documents in JavaScript use the event-driven model of computation User interactions with form elements can be used to trigger execution of scripts –Browsers and HTML/JavaScript Documents Document head gets function definitions and code associated with widgets Document body gets code that is interpreted once, when found by the browser

CP476 Internet Computing JavaScript Client-Side Programming 3 Object Orientation and JavaScript –JavaScript is NOT an OOP language –Not support class-based inheritance –Not support polymorphism –Has prototype-based inheritance JavaScript Objects –JavaScript objects are collections of properties, which are like the members of classes in Java and C++ –Properties can be data properties or method properties –JavaScript has primitives for simple types –All JavaScript objects are accessed through references –All objects appear as lists of property-value pairs, in which properties can be added or deleted dynamically

CP476 Internet Computing JavaScript Client-Side Programming 4 2. What can JavaScript do for client-side programming Menus for Navigation Form Validation Popup Windows Password Protecting Math Functions Special effects with document and background Status bar manipulation Messages Mouse Cursor Effects Links

CP476 Internet Computing JavaScript Client-Side Programming 5 3. General Syntactic Characteristics –For client-side programming, JavaScript scripts will be embedded in HTML documents –Either directly, as the content of the tag whose language attribute is set to "JavaScript " -- JavaScript script – See example roots.html – Or indirectly, as a file specified in the src attribute of, as in <script language = "JavaScript" src = "myScript.js"> See example roots2.html and roots.js What is the difference between the two method? –Identifier form begin with a letter or underscore, followed by any number of letters, underscores, and digits case sensitive 25 reserved words, plus future reserved words –Comments: both // and /* … */

CP476 Internet Computing JavaScript Client-Side Programming 6 –Comments: both // and /* … */ –Scripts are often hidden from browsers that do not include JavaScript interpreters by putting them in special comments <!-- -- JavaScript script – //--> –JavaScript statements usually do not need to be terminated by semicolons, but no hurt if added –Assignment statements – just like C++ and Java – Primitive data types Five types: Number, String, Boolean, Undefined, or Null Number, String, and Boolean have wrapper objects (Number, String, and Boolean) In the cases of Number and String, primitive values and objects are coerced back and fort so that primitive values can be treated essentially as if they were objects

CP476 Internet Computing JavaScript Client-Side Programming 7 Numeric literals – just like Java –All numeric values are stored in double- precision floating point String literals are delimited by either ' or “ –Can include escape sequences (e.g., \t) –Embedded variable names are NOT interpolated –All String literals are primitive values Boolean values are true and false –The only Null value is null –The only Undefined value is undefined –JavaScript is dynamically typed – any variable can be used for anything (primitive value or reference to any object) –The interpreter determines the type of a particular occurrence of a variable –Variables can be either implicitly or explicitly declared var sum = 0, today = "Monday", flag = false;

CP476 Internet Computing JavaScript Client-Side Programming 8 –Numeric operators - ++, --, +, -, *, /, % All operations are in double precision Math Object –floor, round, max, min, trig functions, etc. –The Number Object –Some useful properties: –MAX_VALUE, MIN_VALUE, NaN, POSITIVE_INFINITY, NEGATIVE_INFINITY, PI e.g., Number.MAX_VALUE An arithmetic operation that creates overflow returns NaN –NaN is not == to any number, not even itself –Test for it with isNaN(x) Number object has the method: toString var price = 427, str_price; str_price = price.toString();

CP476 Internet Computing JavaScript Client-Side Programming 9 String catenation operator + var first = ‘This is’; second = first + “ a test”; Coercions “February “ Catenation coerces numbers to strings 7 * “3” Numeric operators (other than +) coerce strings to numbers –Conversions from strings to numbers that do not work return NaN

CP476 Internet Computing JavaScript Client-Side Programming 10 String properties and methods: –length e.g., var len = str1.length; (a property) –charAt(position) e.g., str.charAt(3) –indexOf(string) e.g., str.indexOf('B') –substring(from, to) e.g., str.substring(1, 3) – toLowerCase() e.g., str.toLowerCase() Conversion functions –parseInt(string) and parseFloat(string) –The string must begin with a digit or sign and have a legal number; otherwise NaN is returned The typeof operator –Returns "number", "string", or "boolean" for primitives; returns "object" for objects and null

CP476 Internet Computing JavaScript Client-Side Programming Screen Output –The JavaScript model for the HTML document is the Document object The model for the browser display window is the Window object The Window object has two properties, document and window, which refer to the Document and Window objects, respectively The Document object has a method, write, which dynamically creates content The parameter is a string, often catenated from parts, some of which are variables e.g., document.write("Answer: " + result + " "); –The parameter is sent to the browser, so it can be anything that can appear in an HTML document (, but not \n) –The default object is the current window, so the object need not be included in the call to any of these three

CP476 Internet Computing JavaScript Client-Side Programming 12 –The Window object has three methods for creating dialog boxes, alert, confirm, and prompt alert("Hej! \n"); –Parameter is plain text, not HTML –Opens a dialog box which displays the parameter string and an OK button –It waits for the user to press the OK button confirm("Do you want to continue?"); –Opens a dialog box and displays the parameter and two buttons, OK and Cancel –Returns a Boolean value, depending on which button was pressed (it waits for one) prompt("What is your name?", ""); –Opens a dialog box and displays its string parameter, along with a text box and two buttons, OK and Cancel –The second parameter is for a default response if the user presses OK without typing a response in the text box (waits for OK)

CP476 Internet Computing JavaScript Client-Side Programming Control Statements –Similar to C, Java, and C++. Compound statements are delimited by braces, but compound statements are not blocks –Control expressions – three kinds Primitive values –If it is a string, it is true unless it is empty or "0" –If it is a number, it is true unless it is zero Relational Expressions –The usual six: ==, !=,, = –Operands are coerced if necessary –If one is a string and one is a number, it attempts to convert the string to a number –If one is Boolean and the other is not, the Boolean operand is coerced to a number (1 or 0) –The unusual two: === and !== –Same as == and !=, except that no coercion are done (operands must be identical)

CP476 Internet Computing JavaScript Client-Side Programming 14 –Comparisons of references to objects are not useful (addresses are compared, not values) Compound Expressions –The usual operators: &&, ||, and ! –The primitive values, true and false, must not be confused with the Boolean object properties –If a Boolean object is used in a conditional expression, it is false only if it is null or undefined –The Boolean object has a method, toString, to allow them to be printed (true or false) Selection Statements –The usual if-then-else (clauses can be either single statements or compound statements)

CP476 Internet Computing JavaScript Client-Side Programming 15 Loop statements – while (control_expression) statement or compound – for (init; control; increment) statement or compound init can have declarations, but the scope of such variables is the whole script – do statement or compound while (control_expression)