WEB PROGRAMMING JavaScript.

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

/ 251 Internet Applications Ahmed M. Zeki Sem – / Chapter 8.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
The Web Warrior Guide to Web Design Technologies
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Chapter 2 - Introduction to Java Applications
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to scripting
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Tutorial 10 Programming with JavaScript
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing a Line of Text in a Web Page 7.3 Another JavaScript.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
REEM ALMOTIRI Information Technology Department Majmaah University.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
2.5 Another Java Application: Adding Integers
Project 9 Creating Pop-up Windows, Adding Scrolling Messages, and Validating Forms.
JavaScript: Introduction to Scripting
Chapter 13 - JavaScript/JScript: Introduction to Scripting
Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Objectives Insert a script element Write JavaScript comments
Introduction to C++ Programming
JavaScript: Introduction to Scripting
Chapter 2 - Introduction to Java Applications
JavaScript: Introduction to Scripting
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

WEB PROGRAMMING JavaScript

Introduction JavaScript is used to enhance the functionality and appearance of web pages. JavaScript serves two purposes purposes—it introduces client-side, which makes web pages more dynamic and interactive. it provides the programming foundation for the server-side scripting. Run JavaScript: To allow scripts on Internet Explorer to run in files on your computer, select Internet Options from the Tools menu. Click the Advanced tab and scroll down to the Security section of the Settings list. Check the box labeled Allow active content to run in files on My Computer. Click OK and restart Internet Explorer. Firefox, Chrome, Opera, Safari (including on the iPhone) and the Android browser have JavaScript enabled by default.

First Example

Line 9 uses the <script> tag to indicate to the browser that the text which follows is part of a script. The type attribute specifies the MIME type of the script as well as the scripting language used in the script. Lines 11–12 instruct the browser’s JavaScript interpreter to perform an action, namely, to display in the web page the string of characters contained between the double quotation (") marks (also called a string literal). Every statement ends with a semicolon (also known as the statement terminator). document object allows you to specify text to display in the HTML5 document. the document object’s writeln method to write a line of HTML5 markup in the HTML5 document.

Displaying a Line of Colored Text

Displaying Text in an Alert Dialog

Line 11 in the script uses the browser’s window object to display an alert dialog. The argument to the window object’s alert method is the string to display. The title bar of this Chrome dialog contains the string JavaScript Alert to indicate that the browser is presenting a message to the user. The dialog provides an OK button that allows the user to dismiss (i.e., close) the dialog by clicking the button. To dismiss the dialog, position the mouse cursor (also called the mouse pointer) over the OK button and click the mouse, or simply press the Enter key. We can refresh the page to run the script again.

Escape Sequences

Obtaining User Input with prompt Dialogs – Dynamic Welcome Page

Declarations, Keywords and Variables declaration statement contains the JavaScript keyword var. A variable is a location in the computer’s memory where a value can be stored for use by a script. All variables have a name and value. Identifiers and Case Sensitivity The name of a variable can be any valid identifier. An identifier is a series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ($) that does not begin with a digit and is not a reserved JavaScript keyword. Declarations end with a semicolon and can be split over several lines with each variable in the declaration separated by a comma—known as a comma-separated list of variable names. Several variables may be declared either in one or in multiple declarations. JavaScript Comments A single-line comment that begins with the characters // states the purpose of the variable in the script. A // comment can begin at any position in a line of JavaScript code and continues until the end of the line. Comments do not cause the browser to perform any action when the script is interpreted; rather, comments are ignored by the JavaScript interpreter.

Multiline Comments Assignment Operator String Concatenation Multiline comments begin with the delimiter/* and end with the delimiter */. All text between the delimiters of the comment is ignored by the interpreter. Assignment Operator assigns the value returned by the window object’s prompt method(user value, or the default value or null if the Cancel button is clicked). The =operator is called a binary operator because it has two operands—name and the result of the expression window.prompt("Please enter your name"). String Concatenation JavaScript has a version of the + operator for string concatenation that enables a string and a value of another data type (including string) to be combined.

Adding Integers Function parseInt converts its string argument to an integer.

Validating JavaScript Validation tools report two types of messages—errors and warnings. When you validate previous addition example at www.javascriptlint.com, lines 24–25 produce the warning message: parseInt missing radix parameter Function parseInt has an optional second parameter, known as the radix, that specifies the base number system that’s used to parse the number (e.g., 8 for octal, 10 for decimal and 16 for hexadecimal). number1 = parseInt( firstNumber, 10 ); This prevents numbers in other formats like octal (base 8) from being converted to incorrect values.

Arithmetic

Decision Making: Equality and Relational Operators Conditions in if statements can be formed by using the equality operators and relational operators summarized in Fig. 6.13. The relational operators all have the same level of precedence and associate from left to right. The equality operators both have the same level of precedence, which is lower than the precedence of the relational operators. The equality operators also associate from left to right. Each comparison results in a value of true or false.

Creating and Using a New Date Object Line 12 sets the variable now to a new Date object, which contains information about the current local time. We create a new object by using the new operator followed by the type of the object, in this case Date, and a pair of parentheses.