Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.

Slides:



Advertisements
Similar presentations
/ 251 Internet Applications Ahmed M. Zeki Sem – / Chapter 8.
Advertisements

Introducing JavaScript
The Web Warrior Guide to Web Design Technologies
2440: 211 Interactive Web Programming JavaScript Fundamentals.
CS 898N – Advanced World Wide Web Technologies Lecture 14: JavaScript Chin-Chih Chang
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
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.
JavaScript Friend or Foe?. History of Java and JavaScript Oak and Coffee? ECMAscript European Computer Manufacturers Association JScript?
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
XP Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 1 New Perspectives on Creating Web Pages with HTML Tutorial 8: Programming.
Chapter 2: Introduction to C++.
JavaScript, Third Edition
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
XP 1 JavaScript Creating a Programmable Web Page.
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Programming with JavaScript (Chapter 10). XP Various things Midterm grades: Friday Winter Career Fair – Thursday, April 28, 2011 (11 am to 3 pm). – MAC.
Database-Driven Web Sites, Second Edition1 Chapter 3 INTRODUCTION TO CLIENT-SIDE SCRIPTS.
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.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Chapter 3: Data Types and Operators JavaScript - Introductory.
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.
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.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
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.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
MCA-401: ADVANCE JAVA 1 DEPTT. OF COMP. SC & APPLICATIONS PREPARED BY : NAVEEN NAGPAL (SENIOR ASSISTANT PROFESSOR)
JavaScript Making Web pages come alive. Objectives Be able to read JavaScript scripts Be able to write JavaScript scripts.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Client-Side Scripts JavaScript CIS January 2005.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
1 JavaScript. 2 Introduction to JavaScript JavaScript was designed to add interactivity to HTML pages JavaScript is an interpreted programming (means.
XP Tutorial 10 Section 1 1 Programming with JavaScript.
Web111a_chapt08.ppt HTML: Section 8 JavaScript CGI Programs (Server Side programs) Common Gateway Interface Run on server Communicate with user across.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
1 Server versus Client-Side Programming Server-SideClient-Side.
1 JavaScript in Context. Server-Side Programming.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Tutorial 11 1 JavaScript Operators and Expressions.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
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.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Tutorial 10 Programming with JavaScript
Objectives Insert a script element Write JavaScript comments
T. Jumana Abu Shmais – AOU - Riyadh
Tutorial 10 Programming with JavaScript
Chapter 2: Introduction to C++.
Tutorial 10: Programming with javascript
An Introduction to JavaScript
Presentation transcript:

Working with JavaScript

2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables and Data Working with Dates Working with Expressions and Operators Creating JavaScript Functions Working with Conditional Statements Using Arrays Working with Program Loops Debugging Your JavaScript Programs

3 Introduction to JavaScript Server-side Programs pose problems Client-side Programs were developed to run programs and scripts on the client side of a Web browser

4 The Development of JavaScript JavaScript is a subset of Java Differences between Java and JavaScript: –Java is a compiled language –JavaScript is an interpreted language

5 Comparing Java and JavaScript

6 The Development of JavaScript Jscript is a version of JavaScript supported by Internet Explorer The European Computer Manufacturers Association (ECMA) develops scripting standards –The standard is called ECMAScript but browsers still generally call is JavaScript

7 Inserting JavaScript into a Web Page File Outline the main tasks you want the program to perform first A JavaScript program can either be placed directly in a Web page file or saved in an external text file

8 Inserting JavaScript into a Web Page File Insert a client-side script in a Web page when using the script element Comments are useful for hiding scripts from older browsers Specify alternative content using the nonscript element for browsers that don’t support scripts (or have their script support disabled)

9 Writing Output to the Web Page An object-oriented programming language writes the output by manipulating tasks An action you perform on an object is called a method

10 Writing Output to the Web Page To write text to a Web page, use the following JavaScript commands: document.write(“text”); or document.writeln(“text”)’ Where text is the content to be written to the page. The doucment.write() and document.writeln() methods are identical, except that the document.writeln() method preserves any line breaks in the text string.

11 Working with Variables and Data A variable is a named item in a program that stores information Variable names have restrictions.

12 Working with Variables and Data JavaScript variable types: –Numeric variables –String variables –Boolean variables –Null variables You must declare a variable before using it

13 Working with Variables and Data Numeric variable- any number, such as 13, 22.5, etc –Can also be expressed in scientific notation String variable- any group of text characters, such as “Hello” or “Happy Holidays!” –Must be enclosed within either double or single quotations (but not both) Boolean variable- accepts only true and false values Null variable- has no value at all

14 Declaring a JavaScript Variable You can declare variables with any of the following JavaScript commands: var variable; var variable = value; variable = value; Where variable is the name of the variable and value is the initial value of the variable. The first command creates the variable without assigning it a value; the second and third commands both create the variable and assign it a value.

15 Working with Dates Create a date object to store date information Date Methods

16 Working with Expressions and Operators Expressions are JavaScript commands that assign values and variables Operators are elements that perform actions within expressions –Arithmetic operators: perform simple mathematical calculations –Binary operators: work on two elements in an expression –Unary operators: work on only one variable –Increment operators: can be used to increase the value of a variable by 1 –Assignment operators: used to assign values in expressions

17 Working with Expressions and Operators The Math object is a JavaScript object used for calculations other than simple math

18 Creating JavaScript Functions A function is a series of commands that perform an action or calculates a value A function name identifies a function Parameters are values used by the function

19 Creating JavaScript Functions A group of commands set off by curly braces is called a command block. Command blocks exist for other JavaScript structures in addition to functions.

20 Working with Conditional Statements Conditional statements are commands that run only when specific conditions are met Conditional statements require a Boolean expression –you need one of the following operators to create a Boolean expression: Comparison operator Logical operator Conditional operator

21 Using Arrays An array is an ordered collection of values referenced by a single variable name var variable = new Array (size); Where variable is the name of the array variable and size is the number of elements in the array

22 Working with Program Loops A program loop is a set of instructions that is executed repeatedly –Use program loops to configure a group of commands to be executed a set number of times –The loop uses a counter to track the number of times the command block has been run

23 Working with Program Loops Creating a For loop

24 Working with Program Loops Nesting a For loop

25 Working with Program Loops Creating a While loop

26 Working with Program Loops Nesting a While loop

27 Debugging Your JavaScript Programs Three types of errors: –Load-time errors (occurs when the script is loading) –Run-time errors (occurs when the being executed) –Logical errors (free from syntax and structural mistakes, but result in incorrect results)

28 Common Mistakes You need to debug your program to fix the mistakes Common mistakes include: –Misspelling a variable name –Mismatched parentheses or braces –Mismatched quotes –Missing quotes –Using ( instead of [ –Using = in place of ==

29 Debugging Tools and Techniques To avoid making mistakes and quickly located those you do make: –Write modular code –Use the Microsoft Script Debugger to debug (for use with Internet Explorer) –Use the Netscape JavaScript Console to debug (for use with Netscape)

30 Tips for Writing Good JavaScript Code Use good layout to make your code more readable. Indent command blocks to make them easier to read and to set them off from other code Use descriptive variable names to indicate the purpose of your variables Be careful how you use uppercase and lowercase letters in your code, because JavaScript commands and names are case-sensitive

31 Tips for Writing Good JavaScript Code Add comments to your code to document the purpose of each script Initialize all variables at the top of your script and insert comments describing the purpose and nature of your variables Create customized functions that can be reused in different scripts. Place your customized functions in external files to make them available to your entire Web site