Introducing JavaScript

Slides:



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

Essentials for Design JavaScript Level One Michael Brooks
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
2440: 211 Interactive Web Programming JavaScript Fundamentals.
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.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
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
Javascript and the Web Whys and Hows of Javascript.
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
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.
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,
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.
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.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
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.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Client-Side Scripts JavaScript CIS January 2005.
XP Tutorial 8 Adding Interactivity with ActionScript.
 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.
XP Tutorial 10 Section 1 1 Programming with JavaScript.
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 Server versus Client-Side Programming Server-SideClient-Side.
1 JavaScript in Context. Server-Side Programming.
 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.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
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.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Module 1 Introduction to JavaScript
Tutorial 10 Programming with JavaScript
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript.
Objectives Insert a script element Write JavaScript comments
2.1 Parts of a C++ Program.
WEB PROGRAMMING JavaScript.
PHP.
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
JavaScript: Introduction to Scripting
CIS 136 Building Mobile Apps
Presentation transcript:

Introducing JavaScript

Server-Side and Client-Side Programming Server-side programming Program placed on server that hosts Web site Program then used to modify contents and structure of Web pages

Server-Side and Client-Side Programming Runs programs on user’s computer Programs likely to be more responsive to users complement server-side programming

Server-Side Programming

Client-Side Programming

Combining Client-Side and Server-Side Programming

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

The Development of JavaScript Developed by Sun Microsystems Programs designed to be run within Java interpreters An example of a compiled language JavaScript Developed by NETSCAPE, An interpreted language Internet Explorer supports a version called JScript

Comparing Java and JavaScript

Versions of JavaScript

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

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

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)

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

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.

Working with the Script Element Used to enter scripts into an HTML or XHTML file Syntax <script type="mime-type"> script commands </script>

Writing Output to a Web Document Inserting amir.minai@northampton.ac.uk in a Web document <script type="text/javascript"> document.write(“amir.minai@northampton.ac.uk"); </script>

The document.write() Method One way to send output to the Web document Object Can be any item, including mouse pointer or window scrollbars Method Process by which JavaScript manipulates the features of an object

Understanding JavaScript Rules and the Use of White Space Is case sensitive Ignores most occurrences of extra white space Line breaks occurring within a statement can cause error Good practice to not break a statement into several lines

Supporting Non-JavaScript Browsers noscript element Used by browsers that do not support scripts Syntax <noscript> alternative content </noscript>

Working with Variables A named item in a program that stores information Used to represent values and text strings Values can change as the program runs

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

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

Declaring a Variable Tells JavaScript interpreter to reserve memory space for the variable Statement to declare a variable var variable; Declaring three variables var emLink, userName, emServer;

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.

Declaring a Variable Limits on variable names First character must be either a letter or an underscore character ( _ ) Remaining characters can be letters, numbers, or underscore characters Variable names cannot contain spaces Reserved words cannot be used

Writing a Variable Value to a Web Document Can be used in place of value it contains Writing a text string to a Web page var libName = ”Duston Public Library"; document.write(libName); Plus symbol ( + ) Can be used to combine variable with text string

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

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

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

Creating a Function to Perform an Action Functions Collection of commands that perform an action or return a value Include a function name Include a set of commands that run when function is called Some require parameters

Creating a Function to Perform an Action Syntax of a JavaScript function function function_name(parameters){ JavaScript commands } Calling a function function_name(parameter values)

Functions and Variable Scope Indicates where and how the variable can be used in your application Can be local or global

Functions and Variable Scope Local scope Variable created within a JavaScript function Global scope Variables not declared within functions

Creating a Function to Return a Value For a function to return a value It must include a return statement Syntax of a function that returns a value function function_name(parameters) { JavaScript commands return value; }

Commenting JavaScript Code Comments Explain what your programs are designed to do and how they work Multiline comment /* The showEM() function displays a link to the user’s e-mail address. The username and e-mail server name are entered in reverse order */

Using Comments to Hide JavaScript Code Syntax for hiding script <script type="text/javascript"> <!-- Hide from non-JavaScript browsers JavaScript commands // Stop hiding from older browsers --> </script>

Accessing an External JavaScript File Common practice to Create libraries of functions located in external files Script elements that point to external files are Placed in a document’s head section Extension “.js” Used by external files containing JavaScript commands and functions

Using an External Script

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)

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 ==

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 JavaScript Console to debug (for use with Netscape and Mozilla family of browsers)

Microsoft Debugger Window

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

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