CHAPTER 8 JavaScripts Introduction and the Syntax CSIT225 Internet Programming.

Slides:



Advertisements
Similar presentations
Essentials for Design JavaScript Level One Michael Brooks
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Java Script Session1 INTRODUCTION.
Introduction to JavaScript
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.
got ? Research Project – April 1998 Hang Xia, Mark Wang, Richard S. Chang Updated: R Norman, August 1999.
CS 898N – Advanced World Wide Web Technologies Lecture 14: JavaScript Chin-Chih Chang
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Russell Taylor Lecturer in Computing & Business Studies.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Inline, Internal, and External FIle
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Introduction to scripting
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
+ Java vs. Javascript Jessi Style. + Java Compiled Can stand on its own Written once, run anywhere Two-stage debugging Java is an Object Oriented Programming.
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
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.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
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.
An Introduction to JavaScript Summarized from Chapter 6 of “Web Programming: Building Internet Applications”, 3 rd Edition.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript Syntax, how to use it in a HTML document
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.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
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.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
1 JavaScript in Context. Server-Side Programming.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
Introduction to JavaScript Fort Collins, CO Copyright © XTR Systems, LLC Introduction to JavaScript Programming Instructor: Joseph DiVerdi, Ph.D., MBA.
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Java Script. What is JavaScript ? It is an scripting language, developed by Netscape Navigator. It can be used to replace CGI scripts for client-side.
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.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 15: Java Basics Fundamentals of Web Programming.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
Module 1 Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Intro to JavaScript CS 1150 Spring 2017.
JavaScript an introduction.
JavaScript is a scripting language designed for Web pages by Netscape.
Presentation transcript:

CHAPTER 8 JavaScripts Introduction and the Syntax CSIT225 Internet Programming

UNIT 8 1 CSIT 225 – Internet Programming Where does JavaScript Fit In Today, most of the browsers (IE, N.Navigator,…) bringing together a collection of useful Internet-access tools, such as a web client, mail client, ftp client, a news reader. Also any new tools and packages can be added to the web browsers. These capabilities include an applications programmer's interface (API) for plug-ins.

UNIT 8 2 CSIT 225 – Internet Programming Terminology Plug-ins are program modules that dynamically extend the capability of an browser to handle new types of data and information, along with JavaScript and Java, which allow the addition of flexible programmability to Web pages.

UNIT 8 3 CSIT 225 – Internet Programming Terminology Frames: The ability to divide a window into multiple, independent sections. Java: An object-oriented programming language for distributed applications. JavaScript: A simple, object-based programming (scripting) language used for client side programming. Java Applet: Applets are small applications that are included in Web pages and downloaded on demand to be executed by the client browser.

UNIT 8 4 CSIT 225 – Internet Programming Terminology Class: Class is a term used in object-oriented programming to refer a set of related objects which share common characteristics. Classes, and the ability to create new classes, are what make object-oriented programming a powerful and flexible programming model.

UNIT 8 5 CSIT 225 – Internet Programming Some Features of JavaScript JavaScript Programs Are Built into Web Pages  As opposed to the independent application files used to deliver Java applets to Web browsers, the actual source code for JavaScript scripts can be included directly in Web pages.  This is distinct from Java applets which exist independently of the HTML Web pages. JavaScript Gives Programmers Access To Browser Properties  JavaScript is integrated tightly into HTML and web browsers.  Developers have available to them a wide range of tools and information to interact with the currently-loaded HTML document, as well as the current browser session.

UNIT 8 6 CSIT 225 – Internet Programming Some Features of JavaScript JavaScript exposes properties related to the document windows, the history list, the loaded documents, frames, forms, and links to the programmer. In addition, JavaScript can be used to trap user events, such as changing form values or pointing at links, so that appropriate programs can be developed for each event.

UNIT 8 7 CSIT 225 – Internet Programming Some Features of Java Java and JavaScript: Although they are related—JavaScript borrows most of Java's syntax, for instance—they are fundamentally different and serve different purposes. They are complementary rather than competing with each other. Java is much more than a language for developing Web-based applications. It is designed to compete in a market of full- fledged, general-purpose programming languages such as C, C++, Pascal and FORTRAN.

UNIT 8 8 CSIT 225 – Internet Programming Some Features of Java Java and JavaScript: Java is platform-independent and that it can be used for both applications development and the development of in-line applets, or small applications, for Web pages. Like C++ and Smalltalk, Java is object-oriented and relies heavily on the syntax and style of C++. With this comes the steep learning curve of a high- end object-oriented programming language. Unlike most other general-purpose programming languages, Java is not compiled in the traditional sense.

UNIT 8 9 CSIT 225 – Internet Programming Some Features of Java Java and JavaScript: Instead of compiling to native machine code, the Java compiler converts source code into Java byte codes - a platform-independent representation of the Java program code - which are then run on a machine-dependent runtime interpreter. In this way, developers only need to develop and maintain one set of source code and compile it once, and the code can then be run using the runtime interpreters for any machine. Like all compiled languages, though, this adds the complexity of a compilation cycle to development and, especially, debugging.

UNIT 8 10 CSIT 225 – Internet Programming Some Features of Java Java and JavaScript: However, to a certain degree like other compiled languages, an efficient runtime engine means that Java should offer better performance than general- purpose interpreted scripting languages. Fully Extensible A fundamental feature of true object-oriented languages is that they are extensible. That is, programmers can create their own classes - or groupings of objects and data structures - to extend the basic classes that are part of the programming languages.

UNIT 8 11 CSIT 225 – Internet Programming Some Features of Java Developing Stand-Alone Applications and Applets Java is famous because it can be used to develop applets that are delivered on the World Wide Web and executed in client Web browsers. However, Java can also be used to develop complete, platform-independent GUI applications using the Java runtime interpreter (like applications developed in Delphi, Visual Basic and C++). In contrast to Java, JavaScript joins the ranks of simple, easy-to-use scripting languages. Learning JavaScript is more easier then Java.

UNIT 8 12 CSIT 225 – Internet Programming JavaScript Derived from Java JavaScript owes a lot to Java. Its syntax and basic structure are similar to Java, even if the range of functions and the style of programming can differ greatly. JavaScript started life as Netscape's own scripting language with the name LiveScript, but in late 1995, Sun endorsed the language, and it became JavaScript. JavaScript keeps more than just the basic syntax and structure of Java, it also borrows most of Java's flow constructs and implements some of the same security precautions, such as preventing applets from writing to the local disk.

UNIT 8 13 CSIT 225 – Internet Programming JavaScript An Interpreted Language Unlike Java, JavaScript is an interpreted language. Whereas in Java, source code is compiled prior to runtime, in an interpreted language source code files are executed directly at runtime in JavaScript. Interpreted languages offer several advantages - as well as several drawbacks. Interpreted languages such as JavaScript are generally simpler than compiled languages and are easy to learn. It is often easier to develop, change, and trouble- shoot programs because the need to recompile with each change is removed.

UNIT 8 14 CSIT 225 – Internet Programming JavaScript An Interpreted Language On the negative side, It gives lower performance compared with a compiled language. Not Fully Extensible Unlike Java, JavaScript is not fully extensible. The JavaScript model is one of a limited set of base objects, properties, methods, and data types, which provide enough capabilities to create client-side applications.

UNIT 8 15 CSIT 225 – Internet Programming JavaScript Not Fully Extensible While users can create their own objects and write functions, this is not the same as the classes and inheritance offered in Java and other object- oriented programming languages. Integrated into HTML Where Java is only loosely tied to HTML, JavaScript is tightly integrated into HTML files. Typically, entire scripts are in the same files as the HTML that defines a page and are downloaded at the same time as the HTML files.

UNIT 8 16 CSIT 225 – Internet Programming JavaScript Performs Repetitive Tasks JavaScript is most suited to producing small programs, it is especially well-designed for repetitive, event-invoked tasks. For example, JavaScript is ideal for calculating the content of one field in a form based on changes to the data in another field. Each time the data changes, the JavaScript program to handle the event is invoked, and the new data for the other field is calculated and displayed

UNIT 8 17 CSIT 225 – Internet Programming JavaScript Designed for Programming User Events Because of the way in which JavaScript is integrated into the browser and can interact directly with HTML pages, JavaScript makes it possible to program responses to user events such as mouse clicks and data entry in forms. This adds interactivity to Web pages, makes forms dynamic and can decrease the bandwidth requirements and server load incurred by using forms and CGI programming.

UNIT 8 18 CSIT 225 – Internet Programming JavaScript No Code Hiding Because the source code of JavaScript script presently must be included as part of the HTML source code for a document, there is no way to protect code from being copied and reused by people who view your Web pages. This may be accepted as a weakness of JavaScript.

UNIT 8 19 CSIT 225 – Internet Programming Incorporating JavaScript into HTML At the present time, all JavaScript scripts need to be included as an integral part of an HTML document. To do this the SCRIPT tag should be used. The SCRIPT Tag Including scripts in HTML is simple. Every script must be contained inside a SCRIPT container tag. In other words, an opening tag starts the script and a closing tag ends it: JavaScript program

UNIT 8 20 CSIT 225 – Internet Programming Incorporating JavaScript into HTML Including JavaScript in an HTML File  The first, and easiest, way is to include the actual source code in the HTML file, using the following syntax: JavaScript program Hiding Scripts from Other Browsers  Of course, an immediate problem crops up with this type of SCRIPT container:  In order to avoid the browsers which don't support JavaScript to attempt to display or parse the content of the script, the content should be written between HTML comment tags. <!-- HIDE THE SCRIPT FROM OTHER BROWSERS JavaScript program // STOP HIDING FROM OTHER BROWSERS -->

UNIT 8 21 CSIT 225 – Internet Programming Incorporating JavaScript into HTML Including JavaScript in an HTML File  The first, and easiest, way is to include the actual source code in the HTML file, using the following syntax: JavaScript program Hiding Scripts from Other Browsers  Of course, an immediate problem crops up with this type of SCRIPT container:  In order to avoid the browsers which don't support JavaScript to attempt to display or parse the content of the script, the content should be written between HTML comment tags. <!-- HIDE THE SCRIPT FROM OTHER BROWSERS JavaScript program // STOP HIDING FROM OTHER BROWSERS -->

UNIT 8 22 CSIT 225 – Internet Programming Incorporating JavaScript into HTML Using External Files for JavaScript Programs To make development and maintenance of HTML files and JavaScript scripts easier, the JavaScript scripts can be kept in separate files and using the SRC attribute of the SCRIPT tag to include the JavaScript program in an HTML file. In its simplest form, the SRC construct can be used like this:

UNIT 8 23 CSIT 225 – Internet Programming Incorporating JavaScript into HTML First Example: Listing 2.1 Here's the result: <!-- HIDE FROM OTHER BROWSERS // Output "It Works!" document.writeln("It works! "); // STOP HIDING FROM OTHER BROWSERS -->

UNIT 8 24 CSIT 225 – Internet Programming Incorporating JavaScript into HTML First Example (The Output):

UNIT 8 25 CSIT 225 – Internet Programming Incorporating JavaScript into HTML Comments in JavaScript The line which begins with two slashes, // Output "It Works!“ Is a single-line JavaScript comment similar to those used in C++. Everything after the // until the end of the line is a comment. JavaScript also supports C-style multi-line comments, which start with /* and end with */: /* This is a comment */

UNIT 8 26 CSIT 225 – Internet Programming The Syntax The basic syntax and structure of JavaScript looks familiar to anyone who has used C, C++, or Java. A JavaScript program is built with functions and statements, operators and expressions. The basic command unit is a one-line command or expression followed by a semi-colon; for example: document.writeln("It Works! "); This command invokes the writeln() method, which is part of the document object. The semi-colon indicates the end of the command.

UNIT 8 27 CSIT 225 – Internet Programming The Syntax Command Blocks Multiple commands can be combined into command blocks using curly braces ({ and }). Command blocks are used to group together sets of JavaScript commands into a single unit, which can then be used for a variety of purposes, including loops and defining functions. Example: { document.writeln("Does it work? "); document.writeln("It works! "); }

UNIT 8 28 CSIT 225 – Internet Programming The Syntax Embedded Command Blocks Command blocks can be embedded, as the following lines illustrate. { JavaScript code { More JavaScript code }

UNIT 8 29 CSIT 225 – Internet Programming The Syntax Case Sensitivity In JavaScript, object, property, and method names are case sensitive, as are all keywords, operators, and variable names. In this way, all the following commands are different (and some are illegal): document.writeln("Test"); Document.Writeln("Test"); document.WriteLN("Test");

UNIT 8 30 CSIT 225 – Internet Programming The Syntax Outputting Text In most programming languages, one of the basic capabilities is to output—or display—text. In JavaScript output can be directed to several places including the current document window and pop-up dialog boxes. Output in the Client Window  In JavaScript, programmers can direct output to the client window in sequence with the HTML file. Generating alert and confirm boxes  that include text and one or two buttons.  Text and numbers can also be displayed in text and TEXTAREA fields in a form.

UNIT 8 31 CSIT 225 – Internet Programming The Syntax Outputting Text The document.write() and document.writeln() Methods  The document object in JavaScript includes two methods designed for outputting text to the client window:  write() : Acting like printf(“….”); of C  writeln(): Acting like printf(“\n ….”); of C  In JavaScript, methods are called by combining the object name with the method name:  object-name.property-name Data that the method needs to perform its job is provided as an argument in the parentheses;  for example: document.write("Test"); document.writeln('Test');

UNIT 8 32 CSIT 225 – Internet Programming The Syntax Example 2: Ouputting Text This text is plain. <!-- HIDE FROM OTHER BROWSERS document.write("This text is bold. "); // STOP HIDING FROM OTHER BROWSERS -->

UNIT 8 33 CSIT 225 – Internet Programming The Syntax Example (Output)

UNIT 8 34 CSIT 225 – Internet Programming The Syntax Example 2: Ouputting Text <!-- HIDE FROM OTHER BROWSERS document.writeln("One,"); document.writeln("Two,"); document.write("Three "); document.write("..."); // STOP HIDING FROM OTHER BROWSERS -->

UNIT 8 35 CSIT 225 – Internet Programming The Syntax Example 3 (Output)