Chapter 1 Introduction to JavaScript JavaScript, Third Edition.

Slides:



Advertisements
Similar presentations
CSCI N241: Fundamentals of Web Design Copyright ©2004 Department of Computer & Information Science Introducing XHTML: Module B: HTML to XHTML.
Advertisements

Introducing JavaScript
Website Design.
1 HTML Standards & Compliance. 2 Minimum Required HTML tags: (must go in this order!)
The Web Warrior Guide to Web Design Technologies
History Leading to XHTML
Tutorial 9 Working with XHTML
XHTML1 Building Document Structure. XHTML2 Objectives In this chapter, you will: Learn how to create Extensible Hypertext Markup Language (XHTML) documents.
Tutorial 10 Programming with JavaScript
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
Tutorial 1: Introduction to JavaScript JavaScript - Introductory.
Upgrading to XHTML DECO 3001 Tutorial 1 – Part 1 Presented by Ji Soo Yoon 19 February 2004 Slides adopted from
Developing a Basic Web Page with HTML
Introducing XHTML: Module B: HTML to XHTML. Goals Understand how XHTML evolved as a language for Web delivery Understand the importance of DTDs Understand.
Creating Web Page Forms
© Ms. Masihi 1.  A web page is created using a language called, Hypertext Markup Language, better known as HTML Code.  HTML is a user friendly language.
Chapter 14 Introduction to HTML
Introducing HTML & XHTML:. Goals  Understand hyperlinking  Understand how tags are formed and used.  Understand HTML as a markup language  Understand.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Copyright © cs-tutorial.com. Introduction to Web Development In 1990 and 1991,Tim Berners-Lee created the World Wide Web at the European Laboratory for.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
4 HTML Basics Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and.
Chapter 1 Understanding the Web Design Environment Principles of Web Design, 4 th Edition.
Week 1 Understanding the Web Design Environment. 1-2 HTML: Then and Now HTML is an application of the Standard Generalized Markup Language Intended to.
Chapter 1 XHTML: Part I The Web Warrior Guide to Web Design Technologies.
XHTML1 Building Document Structure Chapter 2. XHTML2 Objectives In this chapter, you will: Learn how to create Extensible Hypertext Markup Language (XHTML)
Learning Web Design: Chapter 4. HTML  Hypertext Markup Language (HTML)  Uses tags to tell the browser the start and end of a certain kind of formatting.
HTML INTRODUCTION, EDITORS, BASIC, ELEMENTS, ATTRIBUTES.
Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and attributes Create.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
JavaScript Tutorial 1 - Introduction to JavaScript WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Introduction to JavaScript (NON.
Fundamentals of Web Design Copyright ©2004  Department of Computer & Information Science Introducing XHTML: Module A: Web Design Basics.
XHTML1 Introduction to Web Pages Chapter 1. XHTML2 Objectives In this chapter, you will: Learn about the World Wide Web (WWW) Create simple Hypertext.
XP Tutorial 9 1 Working with XHTML. XP SGML 2 Standard Generalized Markup Language (SGML) A standard for specifying markup languages. Large, complex standard.
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
XP 1 Creating an XML Document Developing an XML Document for the Jazz Warehouse XML Tutorial.
JavaScript Tutorial 1 - Introduction to JavaScript WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Introduction to JavaScript – A First.
1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.
Lecture: Web Design Assis. Prof. Freshta Hanif Ehsan Faculty of Computer Science Kabul Polytechnic University Spring Semester
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
JavaScript Tutorial 1 - Introduction to JavaScript1 Tutorial 1 Introduction to JavaScript Section A – Programming, HTML, and JavaScript.
Introduction to JavaScript CS101 Introduction to Computing.
4 HTML Basics Section 4.1 Format HTML tags Identify HTML guidelines Section 4.2 Organize Web site files and folder Use a text editor Use HTML tags and.
Copyright © 2003 Pearson Education, Inc. Slide 1-1 Created by Cheryl M. Hughes The Web Wizard’s Guide to XHTML by Cheryl M. Hughes.
 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.
©SoftMoore ConsultingSlide 1 Introduction to HTML: Basic Document Structure.
HTML Basics. HTML Coding HTML Hypertext markup language The code used to create web pages.
JavaScript, Sixth Edition Chapter 1 Introduction to JavaScript.
HTML HYPER TEXT MARKUP LANGUAGE. INTRODUCTION Normal text” surrounded by bracketed tags that tell browsers how to display web pages Pages end with “.htm”
LBSC 690 Session 4 Programming. Languages How do we learn a language? Learn by listening Then reading Then writing How do we teach programming? Learn.
Introduction to the World Wide Web & Internet CIS 101.
Tutorial 9 Working with XHTML. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Describe the history and theory of XHTML.
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.
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
XHTML1 Introduction to Web Pages N100 Building a Simple Web Page.
Web Design Principles 5 th Edition Chapter 3 Writing HTML for the Modern Web.
XHTML Introductory1 Frames Chapter 5. XHTML Introductory2 Objectives In this chapter, you will: Work with the Frameset Document Type Definition (DTD)
Chapter 1 Introduction to JavaScript.  Study the history of the World Wide Web  Work with well-formed Web pages  Learn about Web development  Learn.
Module 1 Introduction to JavaScript
Section 4.1 Section 4.2 Format HTML tags Identify HTML guidelines
About the Presentations
Introducing HTML & XHTML:
An Introduction to JavaScript
Presentation transcript:

Chapter 1 Introduction to JavaScript JavaScript, Third Edition

2 Objectives Study the history of the World Wide Web Work with structured Web pages Learn about the JavaScript programming language Add structure to your JavaScript programs Learn about logic and debugging

JavaScript, Third Edition 3 The World Wide Web and JavaScript World Wide Web’s (WWW) original purpose: –Locate and display information As WWW grew, greater interactivity –Web more useful –New Web programming language needed : JavaScript created to fill programming need

JavaScript, Third Edition 4 The World Wide Web and JavaScript (Cont.) JavaScript: –Considered a critical part of Web page design and authoring –Can turn static documents into applications –Code can change contents of a Web page after a browser has rendered it –Creates visual effects –Can control Web browser window itself None of this was possible before the creation of JavaScript

JavaScript, Third Edition 5 The World Wide Web Internet is vast network that connects computers all over the world Common misconception: –That “Web” and “Internet” are synonymous The Web is only one part of the Internet –Means of communicating on the Internet The Internet is composed of other communication methods –Example: systems that send and receive messages

JavaScript, Third Edition 6 Web Browsers Internet Explorer and Netscape: web browsers Browser wars began over DHTML –DHTML allows a Web page to change after it has been rendered by browser –Examples of DHTML include: change document background color and create effects such as animation Earlier versions of Internet Explorer and Navigator –DHTML elements were incompatible W3C adopted formal standard of DHTML version found in version 4 of Internet Explorer

JavaScript, Third Edition 7 HTML Documents HTML is a simple language –Used to create Web pages that appear on World Wide Web –Based on an older language SGML: Standard Generalized Markup Language Like SGML, HTML originally designed to define elements in a document independent of how they would appear HTML now capable of defining how elements should appear in a browser

JavaScript, Third Edition 8 Basic HTML Syntax HTML documents are text documents –Contain formatting instructions, called tags –Should be defining the contents All HTML documents must use the element as the root element A root element contains all the other elements in a document Opening and closing... tags are required Two other important HTML elements are the element and the element

JavaScript, Third Edition 9 Basic HTML Syntax (Cont.) The element and elements it contains are referred to as document head Following document head is the element –Contains document body –The element and the text and elements it contains are referred to as document body Attributes are used to configure HTML elements syntax attribute=“value” is used to assign a value to an attribute

JavaScript, Third Edition 10 Basic HTML Syntax (Cont.)

JavaScript, Third Edition 11 Creating an HTML Document You can create HTML document in any text editor –Notepad and WordPad –Or in HTML editors like Macromedia Dreamweaver To view final results, open document in a Web browser HTML editors automatically add elements and attributes that may be unfamiliar to you

JavaScript, Third Edition 12 Creating an HTML Document (Cont.) To create a simple HTML document, follow these steps: 1.Start your text editor and create a new document, if necessary 2.Type the following elements to begin the HTML document.

JavaScript, Third Edition 13 Creating an HTML Document (Cont.) 3. Add the following and elements between the... tag pair Central Valley Copy Center 4. Add the following elements above the closing tag 5. Add any text above the closing element

JavaScript, Third Edition 14 Creating an HTML Document (Cont.) Save document as CopyCenter.html Open the CopyCenter.html document in Internet Explorer or another Web browser Close your Web browser window

JavaScript, Third Edition 15 Working with Well-Formed Web Pages HTML is being replaced with XHTML (extensible hypertext markup language) –HTML is useful only for rendering documents in traditional browsers Web is expanding to other media, called user agents: –Devices capable of retrieving and processing HTML and XHTML document HTML is not suitable for user agents

JavaScript, Third Edition 16 XHTML Document Type Definitions-DTDs A well-formed document: –Conforms to rules and requirements of XHTML –Must include a declaration and the,, and elements The declaration: –Belongs in the first line of an XHTML document –Determines the XHTML DTD with which the document complies

JavaScript, Third Edition 17 XHTML Document Type Definitions-DTDs (Cont.) A document type definition (DTD): –Defines the elements and attributes that can be used in a document, along with the rules that a document must follow when it includes them You can use three types of DTDs with XHTML documents: –Transitional –Strict –Frameset

JavaScript, Third Edition 18 XHTML Document Type Definitions-DTDs (Cont.) One of XHTML goals: –Separate the way the HTML is structured from the way the parsed Web page is displayed in the browser To accomplish this goal: –Several commonly used HTML elements and attributes for display and formatting were deprecated There are three types of DTDs: –Transitional DTD –Frameset DTD –Strict DTD

JavaScript, Third Edition 19 XHTML Document Type Definitions-DTDs (Cont.) The three DTDs distinguished in part by degree to which they allow or do not allow deprecated HTML Traditional DTDs –Allow you to use deprecated style elements in your XHTML documents –Only used to create Web pages that use the deprecated HTML elements

JavaScript, Third Edition 20 XHTML Document Type Definitions-DTDs (Cont.) Frameset DTD –Identical to transitional DTD, except it includes the and elements Allows you to split browser window into two or more frames –Frames have been deprecated in favor of tables –However, frameset documents are still widely used

JavaScript, Third Edition 21 XHTML Document Type Definitions-DTDs (Cont.) Strict DTD –Eliminates elements that were deprecated in the transitional DTD and frameset DTD –Always try to use the strict DTD

JavaScript, Third Edition 22 XHTML Document Type Definitions-DTDs (Cont.)

JavaScript, Third Edition 23 Writing Well-formed Documents Well-formed document: –Must include a declaration and the,, and elements Important components: –XHTML documents must use as the root element –XHTML is case sensitive –XHTML elements must have a closing tag –Attribute values must appear within quotation marks –Empty elements must be closed –XHTML elements must be properly nested

JavaScript, Third Edition 24 Writing Well-formed Documents (Cont.) Nesting refers to how elements are placed inside other elements In an HTML document, it makes no difference how the elements are nested In XHTML, each innermost element must be closed before another element is closed

JavaScript, Third Edition 25 Writing Well-formed Documents (Cont.) Three most common empty elements in HTML are: –the element To close an empty element in XHTML: –Add a space and a slash before the element’s closing bracket XHTML documents do not use a root element of

JavaScript, Third Edition 26 Validating Web Pages The Web browser cannot tell whether or not the XHTML document is well formed To ensure that your XHTML document is well formed and its elements are valid: –Use a validating parser Program that checks whether an XHTML document is well formed and whether the document conforms to a specific DTD

JavaScript, Third Edition 27 Validating Web Pages (Cont.) Validation: –Process of verifying that your XHTML document is well formed –Check that document elements are correctly written according to element definitions in a specific DTD If an XHTML document is not validated and contains errors: –Most Web browsers will probably Treat it as an HTML document Ignore the errors Render the page anyway

JavaScript, Third Edition 28 The JavaScript Programming Language JavaScript –Client-side scripting language –Allows Web page authors to develop interactive Web pages and sites –Used in most Web browsers including Internet Explorer

JavaScript, Third Edition 29 The JavaScript Programming Language (Cont.) Client-side scripting –Scripting language that runs on local browser (the client) instead of on Web server Server-side scripting –Scripting language that executes on a Web server

JavaScript, Third Edition 30 The JavaScript Programming Language (Cont.) Some popular server-side scripting languages include: –Common Gateway Interface (CGI), Active Server Pages (ASP), and Java Server Pages (JSP) Scripting language: –Originally, fairly simple programming languages –Today’s Web-based scripting languages are anything but simple

JavaScript, Third Edition 31 The JavaScript Programming Language (Cont.) Browser’s scripting engine: –Executes scripting language code –Just one kind of interpreter Scripting host –Web browser that contains scripting engine –Example: Internet Explorer and Netscape

JavaScript, Third Edition 32 The JavaScript Programming Language (Cont.) JavaScript and Java programming language are entirely different Java –Advanced programming language –Created by Sun Microsystems –Considerably more difficult to master than JavaScript –Java programs are external programs that execute independent of browser In contrast, JavaScript programs run within a Web page and control the browser

JavaScript, Third Edition 33 The Element JavaScript programs –Run from within a Web page (either an HTML or XHTML document) –Code is typed directly into Web page code as separate section –Contained within a Web page are often called scripts The element tells Web browser that the scripting engine must interpret the commands it contains

JavaScript, Third Edition 34 The Element (Cont.) The type attribute of the element –Tells browser which scripting language and which version is being used –You assign a value of “text/javascript” to the type attribute to indicate that the script is written with JavaScript –You include the following code in a document to tell Web browser the statements that follow must be interpreted by JavaScript scripting engine: statements

JavaScript, Third Edition 35 Understanding JavaScript Objects JavaScript is also considered an Object-based programming language An object –Programming code and data that can be treated as individual unit or component A method –Procedures associated with an object A property –Piece of data, such as a color or a name that is associated with an object

JavaScript, Third Edition 36 Understanding JavaScript Objects (Cont.) To incorporate an object and associated method in JavaScript code: –Type the object’s name, followed by a period, followed by the method Many methods need to be provided with more specific information, called an argument, between the parentheses Some methods require numerous arguments, while others don’t require any Providing an argument for a method is referred to as passing arguments

JavaScript, Third Edition 37 Using the write() and writeln() Methods JavaScript treats many things as objects Document object –One of the most commonly used objects in JavaScript programming –Represents browser window’s content To create new text on a Web page –use the write() method or the writeln() method of the Document object Only reason to use the write() and writeln() methods is to add new text to a Web page while it is being rendered

JavaScript, Third Edition 38 Using the write() and writeln() Methods (Cont.) the write() and writeln() methods –Require a text string as an argument –Perform essentially the same function that is performed when a text is manually added to the body of a standard Web page document The only difference between the write() and writeln() methods is that the writeln() method adds a line breaks after the line of text

JavaScript, Third Edition 39 Case Sensitivity in JavaScript JavaScript –Like XHTML, is case sensitive –Within JavaScript code, object names must always be all lower case Comments –Good programming practice to add comments to your code –Nonprinting lines placed in the code to contain various types of remarks

JavaScript, Third Edition 40 Case Sensitivity in JavaScript (Cont.) JavaScript supports two kinds of comments: line comment –Hides single line of code –To create: Add two slashes // before the text you want to use as a comment Block comments –Hide multiple lines of code –To create: Add /* to the first line that you want included in the block Close by typing */ after the last character in the block

JavaScript, Third Edition 41 Structuring JavaScript Code When adding JavaScript code, follow these rules: –Include a Element for Each Code Section –Place JavaScript in the Document Head or Document Body –Create a JavaScript Source File

JavaScript, Third Edition 42 Include a Element for Each Code Section You can include as many script sections as you like within a document. However, when you include multiple script sections in a document –You must include a element for each section

JavaScript, Third Edition 43 Placing JavaScript in the Document Head or Document Body You can place elements in either the document head or document body Where you place your elements varies, depending on the program you are writing The statements in a script are rendered in the order in which they appear in the document

JavaScript, Third Edition 44 Placing JavaScript in the Document Head or Document Body (Cont.) Good idea to place as much of your JavaScript code as possible in document head because: –Head of a document is rendered before the document body –JavaScript code is processed before the main body of the document is displayed –Your code might be performing behind-the-scenes tasks that are required by script sections located in document body

JavaScript, Third Edition 45 Creating a JavaScript Source File You can also save JavaScript code in an external file called a JavaScript source file You can then write a statement in the document that executes (or “calls”) the code saved in the source file When a browser encounters a line calling a JavaScript source file –It looks in the JavaScript source file and executes it

JavaScript, Third Edition 46 Creating a JavaScript Source File (Cont.) A JavaScript source file –Is usually designated by the file extension.js and contains only JavaScript statements –It does not contain a element –To access JavaScript code that is saved in an external file, you use the src attribute of the element

JavaScript, Third Edition 47 Creating a JavaScript Source File (Cont.) A Java Script Source File –You assign to the src attribute the Uniform Resource Locator (URL) of a JavaScript source file –Cannot include XHTML elements –When you specify a source file in your document using the src attribute, the browser ignores any other JavaScript code located within the element

JavaScript, Third Edition 48 Creating a JavaScript Source File (Cont.) There are several reasons to use a.js source file instead of adding the code directly to a document: 1.The document will be neater 2.The JavaScript code can be shared among multiple Web pages 3.JavaScript source files hide JavaScript code from incompatible browsers 4.A combination of embedded JavaScript code and JavaScript source files can be used in the document

JavaScript, Third Edition 49 Hiding JavaScript Code You can enclose the code within a element in an XHTML comment block –Hides embedded code from incompatible browsers Browsers compatible with JavaScript will ignore XHTML comment tags and execute the JavaScript code normally

JavaScript, Third Edition 50 Hiding JavaScript Code (Cont.) JavaScript-compatible browsers never display JavaScript code –Instead, code is interpreted by browser’s scripting engine Only JavaScript comment tags can be used to hide JavaScript code from the interpreter

JavaScript, Third Edition 51 Logic and debugging All programming languages, including JavaScript, have their own syntax, or rules To write a program, you must understand the syntax of the programming language and computer- programming logic The term logic –Refers to the order in which various parts of a program run, or execute

JavaScript, Third Edition 52 Logic and debugging (Cont.) A logical error –Might be multiplying two values when you meant to divide them bug –Any error in a program that causes it to function incorrectly debugging –refers to the act of tracing and resolving errors in a program

JavaScript, Third Edition 53 Chapter Summary HTML documents –Text documents that contain formatting instructions called tags DTDs (Document type definition) –Define elements and attributes that can be used in a document and the rules that a document must follow JavaScript –Client-side scripting language that allows Web pages to be interactive

JavaScript, Third Edition 54 Chapter Summary (Cont.) Object –Programming code and data that can be treated as an individual unit External files –Files that contain JavaScript code –Also called source files

JavaScript, Third Edition 55 W3C Links: JavaScript Reference: JavaScript Tutorial: Validation: