CHAPTER 6 JAVASCRIPT PART 1

Similar documents
Working with JavaScript

<form>. input elements. </form>

Introduction to JavaScript

Outline. Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages

JavaScript Introduction

CISC 1600 Lecture 2.4 Introduction to JavaScript

JavaScript: Introduction, Types

JavaScript s role on the Web

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

Q1. What is JavaScript?

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1

By the end of this section of the practical, the students should be able to:

Just add an HTML comment tag <!-- before the first JavaScript statement, and an end-of comment tag --> after the last JavaScript statement, like this:

CITS1231 Web Technologies. JavaScript

CGS 3066: Spring 2015 JavaScript Reference

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript

Programing for Digital Media EE1707. Lecture 3 JavaScript By: A. Mousavi and P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

JavaScript by Vetri. Creating a Programmable Web Page

Web Development & Design Foundations with HTML5

The first sample. What is JavaScript?

Tutorial 10: Programming with JavaScript

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

JavaScript Introduction

COMS 469: Interactive Media II

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

JavaScript: The Basics

JavaScript code is inserted between tags, just like normal HTML tags:

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

<script type="text/javascript"> script commands </script>

JavaScript CS 4640 Programming Languages for Web Applications

5/19/2015. Objectives. JavaScript, Sixth Edition. Introduction to the World Wide Web (cont d.) Introduction to the World Wide Web

1. Cascading Style Sheet and JavaScript

JavaScript CS 4640 Programming Languages for Web Applications

Exercise 1: Basic HTML and JavaScript

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

CSC Web Programming. Introduction to JavaScript

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Chapter 2 Working with Data Types and Operators

Web Development & Design Foundations with HTML5, 8 th Edition Instructor Materials Chapter 14 Test Bank

Basics of JavaScript. Last Week. Needs for Programming Capability. Browser as Development Platform. Using Client-side JavaScript. Origin of JavaScript

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

COMS 469: Interactive Media II

Programming language components

INF5750. Introduction to JavaScript and Node.js

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

CISH-6510 Web Application Design and Development. Overview of JavaScript. Overview

Web Programming/Scripting: JavaScript

Netscape Introduction to the JavaScript Language

JavaScript Specialist v2.0 Exam 1D0-735

c122mar413.notebook March 06, 2013

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 12

Session 16. JavaScript Part 1. Reading


Lesson 1: Writing Your First JavaScript

(Refer Slide Time: 01:40)

CERTIFICATE IN WEB PROGRAMMING

introjs.notebook March 02, 2014

JavaScript: More Syntax and Using Events

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

Notes on JavaScript (aka ECMAScript) and the DOM

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

JavaScript. What s wrong with JavaScript?

SEEM4570 System Design and Implementation Lecture 03 JavaScript

JavaScript: the language of browser interactions. Claudia Hauff TI1506: Web and Database Technology

CIW 1D CIW JavaScript Specialist.

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

Session 6. JavaScript Part 1. Reading

Shwetank Kumar Gupta

3 The Building Blocks: Data Types, Literals, and Variables

Agenda. My Introduction. CIS 154 Javascript Programming

What is PHP? [1] Figure 1 [1]

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

JavaScript Introduction

Lesson 5: Introduction to Events

Lesson 5: Multimedia on the Web

Chapter 11 Program Development and Programming Languages

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Then there are methods ; each method describes an action that can be done to (or with) the object.

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Produced by. App Development & Modeling. BSc in Applied Computing. Eamonn de Leastar

Client vs Server Scripting

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

Dynamism and Detection

LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

JScript Reference. Contents

5. JavaScript Basics

a Why JavaScript? jonkv interactivity on the web CGI JavaScript Java Applets Netscape LiveScript JavaScript 1: Example

Place User-Defined Functions in the HEAD Section

CS1046 Lab 4. Timing: This lab should take you 85 to 130 minutes. Objectives: By the end of this lab you should be able to:

People = End Users & Programmers. The Web Browser Application. Program Design Phase. Algorithm Design -Mathematical Y = MX + B

A Balanced Introduction to Computer Science, 3/E

Enhancing Web Pages with JavaScript

Introduction to JavaScript Programming Test Bank Chapter 1 with XML and PHP

JavaScript: Introduction to Scripting

JAVASCRIPT. sarojpandey.com.np/iroz. JavaScript

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

Transcription:

CHAPTER 6 JAVASCRIPT PART 1 1

OVERVIEW OF JAVASCRIPT JavaScript is an implementation of the ECMAScript language standard and is typically used to enable programmatic access to computational objects within a host environment JavaScript JScript Action Script netscape microsoft adobe 2

OVERVIEW OF JAVASCRIPT Originally developed by Netscape, as LiveScript Became a joint venture of Netscape and Sun in 1995, renamed JavaScript JavaScript and Java are only related through syntax JavaScript is dynamically typed JavaScript s support for objects is very different JavaScript be embedded in many different things, but its primary use is embedded in HTML documents 3

OVERVIEW OF JAVASCRIPT JavaScript is a scripting language that enables web developers/designers to build more functional and interactive websites. JavaScript is a subset of Java Differences between Java and JavaScript: Java is a compiled language JavaScript is an interpreted language 4

5

OVERVIEW OF JAVASCRIPT The JavaScript Programming Language JavaScript Two formats: Client-side» Program runs on client (browser) Server-side» Program runs on server» Proprietary to web server platform 6

7 WHAT JAVASCRIPT CAN DO? JavaScript gives HTML designers a programming tool JavaScript can put dynamic text into an HTML page A JavaScript statement like this: document.write("<h1>" + name + "</h1>") can write a variable text into an HTML page JavaScript can react to events A JavaScript can be set to execute when something happens, like when a user clicks on an HTML element JavaScript can read and write HTML elements A JavaScript can read and change the content of an HTML element JavaScript can be used to validate data A JavaScript can be used to validate form data before it is submitted to a server-save the server from extra processing 7

JavaScript Syntax The HTML <script> tag is used to insert a JavaScript into an HTML page. The <script> tags tell the browser to expect a script in between them. <html> <body> <script type="text/javascript"> document.write("javascript is not Java"); </script> </body> </html> This part that writes/display the actual text 8

Where to put your scripts? 1. Scripts in <head>. 2. Scripts in <body> 3. Using an External JavaScript 4. In both the body and the head section. 9

<html> Where to put your scripts? <head>. <head> <script type="text/javascript"> function message() { alert("this alert box was called with the onload event"); } </script> </head> <body onload="message()"> </body> </html> 10

Where to put your scripts? <body>. <html> <body> <script type="text/javascript"> document.write("javascript is not Java"); </script> </body> </html> 11

Where to put your scripts? External javascript <html> <head> <script type="text/javascript" src="xxx.js"></script> </head> <body> </body> </html> JavaScript external file with a.js file extension. 12

Where to put your scripts? <head> and <body> <html> <head> <script type="text/javascript"> function message() { alert("this alert box was called with the onload event"); } </script> </head> <body onload="message()"> <script type="text/javascript"> document.write("this message is written by JavaScript"); </script> </body> </html> 13

Writing Output to the Web Page To write text to a Web page, use the following JavaScript commands: document.write( text ); or document.writeln( text ) Where text is the content to be written to the page. The document.write() and document.writeln() methods are identical, except that the document.writeln() method preserves any line breaks in the text string. 14

15 JAVASCRIPT VARIABLES Rules for variable names: Variable names are case sensitive They must begin with a letter or the underscore character You can create a variable with the var statement: var strname = some value You can also create a variable without the var statement: strname = some value Assign a Value to a Variable var strname = "Hege" Or like this: strname = "Hege"

<html> <body> <script type="text/javascript"> var firstname; firstname= Toot"; document.write(firstname); document.write("<br />"); firstname= Tweet"; document.write(firstname); </script> javascript variables <p>the script above declares a variable, assigns a value to it, displays the value, changes the value, and displays the value again.</p> </body> </html> firstname= Toot"; variable value

Working with Variables and Data JavaScript variable types: Numeric variables- 1,2,3, String variables- hello Boolean variables - true and false Null variables- no value at all You must declare a variable before using it 17

Working with Expressions and Operators Expressions are JavaScript commands that assign values and variables Operators are elements that perform actions within expressions 1. Artithmetic Operatorsn ( +,-,* ) 2. Assignment Operators ( =,+= ) 3. Comparison Operators ( ==,>,< ) 4. Logical/boolean Operators ( &&,! ) 5. String Operators txt1="what a very" txt2="nice day!" txt3=txt1+txt2 18

Creating JavaScript Functions A function is a series of commands that perform an action or calculates a value A function name identifies a function Parameters are values used by the function Syntax function functionname(var1,var2,...,varx) { some code } 19

Example javascript function 20

Working with Conditional Statements Conditional statements are commands that run only when specific conditions are met Conditional statements require a Boolean expression you need one of the following operators to create a Boolean expression: Comparison operator Logical operator Conditional operator 21

22 CONDITIONAL STATEMENTS Conditional statements in JavaScript are used to perform different actions based on different conditions. In JavaScript we have three conditional statements: if statement - use this statement if you want to execute a set of code when a condition is true if...else statement - use this statement if you want to select one of two sets of lines to execute switch statement - use this statement if you want to select one of many sets of lines to execute If and If...else Statement You should use the if statement if you want to execute some code if a condition is true.

23 JAVASCRIPTS LOOPING In JavaScript we have the following looping statements: while - loops through a block of code while a condition is true do...while - loops through a block of code once, and then repeats the loop while a condition is true for - run statements a specified number of times 23

JAVASCRIPTS ARRAY An array is an ordered collection of values referenced by a single variable name var variable = new Array (size); Where variable is the name of the array variable and size is the number of elements in the array var faq = new Array(3) faq[0] = "What are JavaScript arrays" faq[1] = "How to create arrays in JavaScript?" faq[2] = "What are two dimensional arrays?" 24

JavaScript Popup Boxes Alert alert("hey, remember to tell your friends about Quackit.com!"); Confirm confirm("are you sure you want to delete the Internet?"); Prompt prompt("message","default response");prompt('please enter your favorite website', 'Quackit.com'); 25

event handler JavaScript are often event-driven. That is, a piece of codes (called event handler) fires in response to a certain user's or browser's action, which generates an event. The commonly-used events are: 1. click: generated when the user clicks on an HTML element. 2. mouseover, mouseout: generated when the user positions the mouse pointer inside/away from the HTML element. 3. load, unload: generated after the browser loaded a document, and before the next document is loaded, respectively. 26

Objects JavaScript is object-oriented, although it does not support all the OO features, so as to keep the language simple. JavaScript's OO is prototype-based, instead of class-based. A class-based OO language (such as Java/C++/C#) is founded on concepts of class and instance. A class is a blue-print or prototype of things of the same kind. An instance is a particular realization (instantiation, member) of a class. For example, "Student" is a class; and "Tan Ah Teck" is an instance of the "Student" class. In a classbased OO language, you must first write a class definition, before you can create instances based on the class definition. A prototype-based OO language (such as JavaScript) simply has objects (or instances). It uses a prototype as a template to get the initial properties of a new object. In JavaScript, you do not have to define a class explicitly. Instead, you define a constructor method to create objects (or instances) with a set of initial properties. Furthermore, you can add or remove properties of an object at runtime, which is not permitted in class-based OO languages. 27

END OF PART 1 28