Introduction to scripting

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.
The Web Warrior Guide to Web Design Technologies
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
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.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
4.1 JavaScript Introduction
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.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
 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.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Ch 6: JavaScript Introduction to scripting part 2.
Week 1 Algorithmization and Programming Languages.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
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.
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.
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.
CGS 3066: Web Programming and Design Spring 2017
Chapter 6 JavaScript: Introduction to Scripting
JavaScript: Introduction to Scripting
Chapter 13 - JavaScript/JScript: Introduction to Scripting
Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
JavaScript: Introduction to Scripting
WEB PROGRAMMING JavaScript.
JavaScript: Introduction to Scripting
T. Jumana Abu Shmais – AOU - Riyadh
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:

Introduction to scripting Ch 6: Java script Introduction to scripting

Chapter outline: In this chapter you will learn: To write simple JavaScript programs. To use input and output statements. Basic memory concepts. To use arithmetic operators. The precedence of arithmetic operators. To write decision-making statements. To use relational and equality operators.

6.1 Introduction JavaScript Scripting language that facilitates a disciplined approach to designing computer programs that enhance the functionality and appearance of web pages. A programming code in java-like language is embedded in the html document and is run as soon as you open the web page. This allows the web page to look differently (more dynamic) depending on the code written. Before you can run code examples with JavaScript on your computer, you may need to change your browser’s security settings. IE prevents scripts on the local computer from running by default All other browsers enable JavaScript by default

Fig. 6.1 | Enabling JavaScript in Internet Explorer

6.2 Simple Program: Displaying a Line of Text in a Web Page JavaScripts appear in the <head> section of the HTML document The <script> tag indicates to the browser that the text that follows is part of a script. Attribute type specifies the scripting language used in the script—such as text/javascript Code in the JavaScript doesn’t have a main function and the statements inside the script element is run one-by-one. Browser’s document object represents the HTML document currently being displayed in the browser Allows a script programmer to specify HTML text to be displayed in the HTML document Browser contains a complete set of objects that allow script programmers to access and manipulate every element of an HTML document

6.2 Simple Program: Displaying a Line of Text in a Web Page Object Resides in the computer’s memory and contains information used by the script The term object normally implies that attributes (data) and behaviors (methods) are associated with the object An object’s methods use the attributes’ data to perform useful actions for the client of the object—the script that calls the methods

6.2 Simple Program: Displaying a Line of Text in a Web Page The parentheses following the name of a method contain the arguments that the method requires to perform its task (or its action) Every statement should end with a semicolon (also known as the statement terminator), although none is required by JavaScript JavaScript is case sensitive Not using the proper uppercase and lowercase letters is a syntax error JavaScript code should be put inside an HTML comment so old browsers that doesn’t support scripts don’t display the code. The end tag of a comment should be commented by // so it doesn’t cause error in the code.

6.2 Simple Program: Displaying a Line of Text in a Web Page The document object’s writeln method Writes a line of HTML text in the HTML document Does not guarantee that a corresponding line of text will appear in the HTML document. Text displayed is dependent on the contents of the string written, which is subsequently rendered by the browser. Browser will interpret the HTML elements as it normally does to render the final text in the document

6.2 Simple Program: Displaying a Line of Text in a Web Page <!DOCTYPE html> <html> <head> <title>A First Program in JavaScript</title> <script type=“text/javascript”> <!-- document.writeln(“<h1>Welcome to JavaScript Programming!</h1>”); // --> </script> </head> <body> </body> </html>

6.3 Modifying Our First Program <!DOCTYPE html> <html> <head> <title>A First Program in JavaScript</title> <script type=“text/javascript”> <!-- document.write(“<h1 style =‘color:magenta’>”); document.write(“Welcome to JavaScript” + “Programming!</h1>”); // --> </script> </head> <body> </body> </html> Unlike the method writeln it does not position the output cursor in the HTML document at the beginning of the next line after writing The + operator is used to concatenate two strings

6.3 Modifying Our First Program Dialogs Useful to display information in windows that “pop up” on the screen to grab the user’s attention Typically used to display important messages to the user browsing the web page Browser’s window object uses method alert to display an alert dialog Method alert requires as its argument the string to be displayed Dialogs display plain text; they do not render HTML. Therefore, specifying HTML elements as part of a string to be displayed in a dialog results in the actual characters of the tags being displayed. window.alert(“Welcome to\n JavaScript \n Programming”);

6.3 Modifying Our First Program

6.4 Obtaining User Input with prompt Dialogs Scripting Gives you the ability to generate part or all of a web page’s content at the time it is shown to the user Such web pages are said to be dynamic, as opposed to static, since their content has the ability to change

6.4 Obtaining User Input with prompt Dialogs Keywords are words with special meaning in JavaScript Keyword var Used to declare the names of variables A variable is a location in the computer’s memory where a value can be stored for use by a program All variables have a name, type and value, and should be declared with a var statement before they are used in a program A variable name can be any valid identifier consisting of letters, digits, underscores ( _ ) and dollar signs ($). Variable names can not begin with a digit and can not be reserved JavaScript keyword. var num1,num2; var num1; Var num2;

6.4 Obtaining User Input with prompt Dialogs Comments A single-line comment begins with the characters // and terminates at the end of the line Multiline comments begin with delimiter /* and end with delimiter */ All text between the delimiters of the comment is ignored.

6.4 Obtaining User Input with prompt Dialogs null keyword Signifies that a variable has no value null is not a string literal, but rather a predefined term indicating the absence of value Writing a null value to the document, however, displays the word “null” Function parseInt converts its string argument to an integer JavaScript has a version of the + operator for string concatenation that enables a string and a value of another data type (including another string) to be concatenated

6.4 Obtaining User Input with prompt Dialogs In JavaScript the + operator is used for Concatenation of a string and a value of another data type (including another string). var str = “ISC”; var num = 52; document.writeln(str + “ 340”); document.writeln(“Section” + num); Arithmetic addition. document.writeln(5 + 2);

6.4 Obtaining User Input with prompt Dialogs The window object’s prompt method displays a dialog into which the user can type a value. The first argument is a message (called a prompt) that directs the user to take a specific action. The optional second argument is the default string to display in the text field. A variable is assigned a value with an assignment statement, using the assignment operator, =. The script can then use the value that the user inputs.

6.4 Obtaining User Input with prompt Dialogs <!DOCTYPE html> <html> <head> <script type="text/javascript"> <!-- var name; name = window.prompt("Please enter your name"); document.writeln("<h1>Hello, " + name + ", welcome to JavaScript programming!</h1>"); // --> </script></head> <body><p>Click Refresh (or Reload) to run this script again.</p> </body></html>