JAVASCRIPT PROGRAMMING LANGUAGE. Introduction JavaScript is a scripting language. The term scripting language refers to programming languages that are.

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

Introducing JavaScript
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
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
HTML Recall that HTML is static in that it describes how a page is to be displayed, but it doesn’t provide for interaction or animation. A page created.
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.
Tutorial 1: Introduction to JavaScript JavaScript - Introductory.
Introduction To JavaScript What JavaScript Is: a general purpose scripting language that allows a static page to interact with users and respond to events.
Introduction to scripting
Javascript and the Web Whys and Hows of Javascript.
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.
Introduction to JavaScript 11 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 14.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
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.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
JavaScript Tutorial 1 - Introduction to JavaScript WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Introduction to JavaScript – A First.
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.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
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.
 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.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript, Fourth Edition
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.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
1 JavaScript in Context. Server-Side Programming.
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.
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.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Module 1 Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
14 A Brief Look at JavaScript and jQuery.
WEB PROGRAMMING JavaScript.
PHP.
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
An Introduction to JavaScript
Introduction to Programming and JavaScript
Presentation transcript:

JAVASCRIPT PROGRAMMING LANGUAGE

Introduction JavaScript is a scripting language. The term scripting language refers to programming languages that are executed by an interpreter from within a Web browser. An interpreter translates programming code into an executable format each time the program is run – one line at a time. Programs written in scripting languages, such as JavaScript, are interpreted when a scripting engine loads an HTML page.

The JavaScript language was first introduced in Navigator and was originally called LiveScript. With the release of Navigator 2.0, the name was changed to JavaScript 1.0. Subsequently, Microsoft released its own version of JavaScript in Internet Explorer 4.0 and named it Jscript. Introduction (Continued)

JavaScript’s Role on the Web JavaScript brings HTML to life and makes Web pages dynamic. Instead of HTML documents being static, JavaScript can turn them into applications, such as games or order forms. You can use JavaScript to change the contents of a Web page after it has been rendered by a browser, to interact with a user through forms and controls, to create visual effects such as animation, and to control the web browser window itself. None of these things was possible before the creation of JavaScript.

JavaScript is available in two formats: Client-side JavaScript and Server-side JavaScript. The standardized client-side JavaScript is the format available to HTML pages displayed in Web browsers (the client). JavaScript version 1.2 in Navigator 4.0 and ECMScript are client-side versions of JavaScript. Server-side JavaScript is used with Web servers to access file systems, communicate with other applications, access databases, and perform other tasks. JavaScript’s Role on the Web

Script Beginning JavaScript Programs run from within an HTML document. The statements that make up a JavaScript program in an HTML document are contained between the ….. tag pairs. The tag is used to notify the Web Browser that the commands that follow it need to be interpreted by a scripting engine. The LANGUAGE attribute of the tag tells the browser which scripting language and which version of the scripting language is being used. JAVASCRIPT STATEMENTS;

First JavaScript Program <Script Language=“JavaScript1.4” Document.writeln(“Hello World”>; //Print on the screen Document.write(“This line is printed below the ‘Hello World’ line.”); [Note: The write() and writeln() methos of the document object require a text string as an argument.]

Structure of JavaScript Programming … Define any function Use defined function Should be : “javascript” OR JavaScript

Multiple JavaScript Calls <Script Language="JavaScript" SRC="source.js"> document.writeln("This line was created with embedded JavaScript code."); document.writeln("This line was also created with embedded JavaScript code."); Internal and External Source for print document.write("this line was printed from the JavaScript spurce file.") Save the file as JavaScriptsource.js

Adding Comments to a JavaScript Program /* This line is part of the block comment. This line is also part of the block comment */ Document.writeln(“somments Example”); //Line comments con follow code statements //This line comment takes up an entire line. /*This is another way of creating a block comment.*/

Hiding JavaScript from Incompatible Browsers This line is rendered normally since it is located before the opening comment tag. <!- - text on this line is not displayed Text on this line is not displayed This line is not displayed either --> This line is rendered normally since it is located after the closing comment tag.

Multiple JavaScript Calls <Script Language="JavaScript" <!– Begin Hiding JavaScript  mylink= "C:\Documents and Settings\Administrator\Desktop\1.html" click here

Variables, Functions, Objects, and Events

Variable One of the most important aspects of programming is the ability to store and manipulate values in computer memory location. The values stored in computer memory locations are called variables. In JavaScript, you use the reserved keyword Var to create variable. Reserved word, or keywords, are part of the JavaScript language syntax. Reserved words cannot be used for variable names. Abstract Char Do FinallyBoolean Class Double Float Break ConstElse For Byte Continue Extends FunctionCase Default False Goto Catch DeleteFinal If Implements New Static True Import Null Super Try Import Null Super Try In Package Switch Typeof Instanceof Public Throw While Long ReturnThrows With Native Short Transient

The value you assign a variable can be a literal string or a numeric value. Var myvariable=“Hello”; String Var myvariable=100; numeric You can declare multiple variables in the same statement using a single Var keyword: Var firstvar=“text”, secondvar=100, thirdvar=2.5; Ex. Var myDog=“Golden Retriever”; Document.writeln(myDog); myDog=“Irish Setter”; document.writeln(myDog);

var name = prompt("Enter your name", "Name"); document.write(" Hello " + name + " "); USER INPUT

To Display String and Number Script document.write("JavaScript") document.write("Hello everybody") document.write(1000)

Simple Convert on Hexadecimal Value Integer Integral Value with String document.write( " ") document.write(2*125 + " " "Aptech")

Hexadecimal to Binary Hexadecimal Code This Hexadecimal Code convert to Binary. document.write(" " + " ") document.write("Notebook" + 10e5) document.write(" " + "Good Morning" + " " + 10e-5)

Print Number Print Numbers var integervar = 150; var floatingpointvar = 3.0e7; document.writeln(integervar); document.writeln(floatingpointvar);

Variable Calculation Variable var a = "Ram has scored"; var b = 100; var c = "in Final"; var d = a+b+c; var e = 100; document.writeln(" "); document.writeln(" " + a + b ); document.writeln(" " + d + " " + " "); document.writeln("Total" + c + "is" + b + e + " ");

Variable Calculation Variable calculation Variable var a = 100; var b = -109; var c = 15; var d = a*c; var e = a/c;

document.writeln(" " + " "); document.writeln("a+b" + "=" + (a+b)); document.writeln(" " + "a-b" + "=" + (a-b)); document.writeln(" " + "(a+b-e)" + "=" + (a+b-e)); document.writeln(" " + "(a*b-d)" + "=" + (a*b-d)); document.writeln(" " + "(a/b*c)" + "=" + (a/b*c)); document.writeln(" ");

Variable Calculation var name="anil"; var salary=900; var da=90; var hra=90; var totalsalary=salary+da+hra; document.write(" "+"name is" +name+" "); document.write(" "+"da is"+da +" "); document.write(" "+"hra is" +hra+" "); document.write(" "+"total salary is" + totalsalary+" ");

Define Global Variable Variable scope var First_Global_Variable = "First Global Variable"; function Scope_Example() { Second_Global_Variable = "Second Global Variable"; var Local_Variable = "Local Variable"; document.writeln(First_Global_Variable); //prints successfully document.writeln(Second_Global_Variable); //prints successfully document.writeln(Local_Variable); //prints successfully }

Scope_Example(); document.writeln(First_Global_Variable); //prints successfully document.writeln(Second_Global_Variable); //prints successfully document.writeln(Local_Variable); //error message

Table Inside Function document.write(" "); document.write(" name "); document.write(" ram "); document.write(" address "); document.write(" bkt "); document.write(" phone "); document.write(" ");

Defining Functions: Individual statements used in a computer program are often grouped into logical units called procedures. In JavaScript programming, procedures are called functions. The lines that compose a function within an HTML document are called the function definition. The syntax for defining a function is: Function name_of_function (parameters) { Statements; } A function definition consists of three parts: 1.The reserved word function followed by the function name. The reserved word function notified the JavaScript interpreter that the code that follows is a function. As with variables, the name you assign to a function is called an identifier. The same rules and conventions that apply to variable names apply to function names. 2.Any parameters required by the function, contained within parentheses following the function name. 3.The function’s statements, enclosed in curly braces{ }

Function that prints the name of multiple companies Function print_company_name(company1, company2, company3) { document.writeln(company1); document.writeln(company2); document.writeln(company3); }

To create a JavaScript Program that Print Company Name: Two Functions Program <Script Language=“JavaScript” <!- - Hide from incompatible Browsers Function print_conpany_name(company_name) { document.writeln( company_name ); } //Stop Hiding from Incompatible Browsers - ->

Typeof Function type of function (to define character or number typeof() var a = 150; var b = "MOTHER"; document.writeln("Type of a is" + typeof(a)); document.writeln(" " + typeof(a)); document.writeln(" " + "type of b is" + b + typeof(b));

<!– Hide from incompatible browsers Print_ company_name(“my company”); //Stop Hiding from incompatible browsers - ->

To Create a JavaScript Program that contains two functions: Two Function Program <!- - Hide from incompatible browsers Function print_message(first_message) { document.writeln(first_message); } Function return_message(second_message) { return “This message was returned from a function”; } //Stop Hiding from Incompatible Browsers - ->

<!– Hide from incompatible browsers Print_ message(“’This text was printed from a function”); var return_value = return_message(); document.writeln(return_value); //Stop Hiding from incompatible browsers - ->

USING EVENTS One of the primary ways in which JavaScript makes HTML documents dynamic is through events. You can use JavaScript events to add interactivity between your Web pages and users. An event is specific circumstance that is monitored by JavaScript. The most common events are actions that users take. EVENTTriggered when About The loadihng of an image is interrupted Blur An elemet, such as a radio button, because inactive Click An element is clicked onces Change The calue of an element changes Error There is an erroe when loading a document or image

Focus An element because active Load A socument or image loads MouseOut The mouse moves off an element MouseOver The mouse moves an element Reset A form resets Select A user selects a field in a form Submit A user submits a form Unload A document unloads

HTML Tags and Events Element Description Events … Link Click MouseOver MouseOut Image About Error Load area MouseOver MouseOut … Document body Blur Error

Focus Load Unload … Frame set Blur Error Focus Load Unload … Frame Blur Focus … Form Submit Reset Text Field Blur Focus change

Select … Text area Blur focus change select Submit Click Reset Click Radio Click Checkbox Click … Selection Blur Focus Change

Viewing the array elements of a JavaScript Array <!-- Begin Hiding JavaScript friends = new Array(5); friends[0] = "Ananth"; friends[1] = "Cedric"; friends[2] = "Ketan"; document.write(friends[0]+" "); document.write(friends[1]+" "); document.write(friends[2]+" "); join_crit = friends.join(); document.write(join_crit); // End hiding JavaScript -->

Creating and Using User Defined Functions var name = ""; function hello( ) { name = prompt('Enter Your Name:','Name'); alert('Greetings ' + name + ', Welcome to my page!'); } function goodbye( ) { alert('Goodbye ' + name + ', Sorry to see you go!'); }

Outputting Text Silicon Chip Technologies. document.write(" "); document.write(' '); document.write(" Silicon Chip Technologies. ")

EXAMPLE alert("Welcome To My Web Site!"); document.write(' ');

Example 2.6 document. write(' '); document. write(" Greetings,"); document.write(prompt("Enter Your Name:","Name")); document.write(".Welcome to My HomePage! ");