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

Similar documents
Lecture 17. History, Navigator, Screen and Form Objects. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Princess Nourah bint Abdulrahman University. Computer Sciences Department

A Balanced Introduction to Computer Science, 3/E

A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN


Functions, Randomness and Libraries

Introduction to JavaScript

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

The first sample. What is JavaScript?

Lecture 13. Page Layout. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Session 16. JavaScript Part 1. Reading

Q1. What is JavaScript?

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

Session 6. JavaScript Part 1. Reading

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

JavaScript Introduction

Working with JavaScript

Place User-Defined Functions in the HEAD Section

Coding in JavaScript functions

Web Programming/Scripting: JavaScript

JavaScript: The Basics

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

CSC Web Programming. Introduction to JavaScript

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

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

JavaScript s role on the Web

The JavaScript Language

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

Client vs Server Scripting

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

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

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

CGS 3066: Spring 2015 JavaScript Reference

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

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

JavaScript Introduction

<form>. input elements. </form>

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

JavaScript CS 4640 Programming Languages for Web Applications

CHAPTER 6 JAVASCRIPT PART 1

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

Lesson 1: Writing Your First JavaScript

About the Author. Liability

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

New Media Production Lecture 7 Javascript

LECTURE-2. Functions review HTML Forms. Arrays Exceptions Events. CS3101: Scripting Languages: Javascript Ramana Isukapalli

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

CSC Javascript

Web Development & Design Foundations with HTML5

CSS The web browser uses its own resources, and eases the burden on the server. It has fewer features than server side scripting.

EXERCISE: Introduction to client side JavaScript

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

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

Javascript Lecture 23

JavaScript CS 4640 Programming Languages for Web Applications

Lecture 10. CSS Properties. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

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

Chapter 2 Working with Data Types and Operators

Such JavaScript Very Wow

A Balanced Introduction to Computer Science, 3/E

JAVASCRIPT BASICS. JavaScript Math Functions. The Math functions helps you to perform mathematical tasks

Lecture 08. Tables in HTML. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

SEEM4570 System Design and Implementation Lecture 03 JavaScript

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

CMPT 100 : INTRODUCTION TO

JavaScript by Vetri. Creating a Programmable Web Page

710 Index Attributes, 127 action attribute, 263 assigning, bottom attribute, domain name attribute, 481 expiration date attribute, 480 8

Background. Javascript is not related to Java in anyway other than trying to get some free publicity

Variables, Types, Operations on Numbers

Chapter 1 Introduction to Computers and the Internet

5. JavaScript Basics

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

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

Note: Java and JavaScript are two completely different languages in both concept and design!

JAVASCRIPT. sarojpandey.com.np/iroz. JavaScript

Web Site Design and Development JavaScript

Client-Side Web Technologies. JavaScript Part I

Events: another simple example

Fundamentals of Website Development

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

COSC 122 Computer Fluency. Programming Basics. Dr. Ramon Lawrence University of British Columbia Okanagan

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

Princeton University COS 333: Advanced Programming Techniques A Subset of JavaScript

COMP519 Practical 5 JavaScript (1)

Web Design and Application Development

CS 302: Introduction to Programming

AP Computer Science. Return values, Math, and double. Copyright 2010 by Pearson Education

JavaScript Introduction

(Refer Slide Time: 01:40)

CITS1231 Web Technologies. JavaScript

3Lesson 3: Functions, Methods and Events in JavaScript Objectives

Lesson 7: If Statement and Comparison Operators

CISC 110 Week 3. Expressions, Statements, Programming Style, and Test Review

PIC 40A. Midterm 1 Review

The JavaScript Language

CS110: PROGRAMMING LANGUAGE I

JavaScript Handling Events Page 1

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

Transcription:

Lecture 14 Introduction to JavaScript Mr. Mubashir Ali Lecturer (Dept. of dr.mubashirali1@gmail.com 1

Outline What is JavaScript? Embedding JavaScript with HTML JavaScript conventions Variables in JavaScript JavaScript operators Input output in JavaScript JavaScript functions Conditional Statements Looping Statements 2

1. JavaScript JavaScript is a client-side scripting language JavaScript was designed to add interactivity to HTML pages JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create cookies, and much more 3

1. JavaScript. JavaScript is an interpreted language (means that scripts execute without preliminary compilation) JavaScript is usually embedded directly into HTML pages Everyone can use JavaScript without purchasing a license 4

1. JavaScript. JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Mozilla, Firefox, Netscape, Opera 5

1.1 JavaScript: Common uses JavaScript gives HTML designers a programming tool JavaScript can react to events JavaScript can read and write HTML elements JavaScript can be used to validate data JavaScript can be used to detect the visitor's browser JavaScript can be used to create cookies 6

2. Embedding JavaScript in HTML There are two methods to embed JavaScript in to HTML code Internal Script: directly written in HTML code External Script: written in separate file <script> tag is used to tell the browser that a script follows 7

2.1 Internal Scripts The <SCRIPT> tag is used to embed JavaScript code in HTML documents <SCRIPT LANGUAGE="JavaScript"> [JavaScript Statements...] </SCRIPT> JavaScript can be placed anywhere between <HTML> and </HTML> tags two possibilities are the <HEAD> </HEAD> portion and the <BODY> </BODY> portion 8

2.1 Internal Scripts <HTML> <HEAD><TITLE>Using Multiple scripts</title> <SCRIPT LANGUAGE="JavaScript"> [JavaScript statements...] </SCRIPT> <SCRIPT LANGUAGE="JavaScript"> [JavaScript statements...] </SCRIPT> </HEAD> <BODY> <H1>This is another script</h1> <SCRIPT LANGUAGE="JavaScript"> [JavaScript statements...] </SCRIPT> </BODY></HTML> 9

2.2 External Script We place script in a separate file and include this in HTML code SRC attribute of the <SCRIPT> is used to include the external JavaScript file in HTML <script src="myscripts.js"> </script> Are useful when you have lengthy scripts Improve the readability 10

3. JavaScript Conventions Using the Semicolon document.write("hello"); alert("good bye") document.write("hello") alert("good bye") document.write("hello"); alert("good bye"); Case Sensitivity Comments: single line // Multiple lines /* */ 11

3. JavaScript Conventions Using Quotes document.write( <font color= red >Hello World</font> ) document.write( <font color= red >Hello World</font> ) 12

4. Writing JavaScript Start of JS script Writing on webpage HTML code in JS End of JS script 13

4. Writing JavaScript Out put of the JS code 14

4.1 Variables in JavaScript Variable is the name of a memory location which holds the data of a certain type (data types) There are four common data types in JavaScript numbers, strings, Boolean, null values JavaScript is a loosely typed language 15

4.1 Variables in JavaScript The word var is used to declare a variable var LastName = Smith var AccountNumber = 1111 Variable Naming First character can not be a digit Other characters may be digits, letters or underscore Reserved words can not be used Case sensitive 16

4.1 Variables in JavaScript Variable Initialization var variablename = initialvalue var variablename1 = initialvalue1, variablename2 = initialvalue2, 17

5. JavaScript Operators An operator is simply a symbol that tells the compiler (or interpreter) to perform a certain action Assignment Operator: = Arithmetic Operators: +, -, *, /, %, ++, -- Logical Operators: &&,,! Comparison Operators: ==, ===,!=,!==, <, >, <=, >= 18

6. Input Out put in JavaScript write(); is used to write on browser document.write( hello world ) document.write(a) prompt(); is used to take input from users var num = prompt( Please Enter a Number, 0)

6. Input Out put in JavaScript Start of JS code End of Script Writing on browser User input 20

7. JavaScript Function User defined functions Predefined functions 21

7. JavaScript Function Functions are defined using the keyword function, followed by the name of the function and list of parameters function functionname([parameters]) { [statements] } 22

7. JavaScript Function Calling a function The syntax of a function call is: functionname([arguments]) 23

7. JavaScript Function Start of the function Asks user to enter name Writes name on the webpage Calling a function 24

7. JavaScript Function Common events onclick ondblclick onchange onfocus onmouseover onmouseout onsubmit onload 25

7. JavaScript Function Some common predefined math functions Math.sqrt Math.pow Math.abs Math.max Math.min Math.floor Math.ceil Math.round Math.random 26

8. Conditional Statements If statement if (condition) statement if(condition) { statements } If-else statement if(condition) {statement} else {statements} 27

8. Conditional Statements Random number is generated )*10 User s Input If condition 28

8. Conditional Statements On click event text 29

9. Loops For loop for(var i=1; i<10; i++) { Document.write( hello world ) } While loop While(condition) { } 30

9. Loops For loop Do-while loop 31

9. Loops Output of for loop Output of dowhile loop 32

Summary What is JavaScript? Embedding JavaScript with HTML JavaScript conventions Variables in JavaScript JavaScript operators Input output in JavaScript JavaScript functions Conditional Statements Looping Statements 33

References Chapter 11. Beginning HTML, XHTML,CSS, and JavaScript, by Jon Duckett, Wiley Publishing; 2009, ISBN: 978-0-470-54070-1. Chapter 2, Learn JavaScript, by Chuck Easttom, Wordware Publishing; 2002, ISBN 1-55622-856-2 34