Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.

Slides:



Advertisements
Similar presentations
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
JavaScript Bartosz Sakowicz. JavaScript - basics JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction To JavaScript What JavaScript Is: a general purpose scripting language that allows a static page to interact with users and respond to events.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Introduction to scripting
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
DOM and JavaScript Aryo Pinandito.
History, Navigator, Screen and Form Objects Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
Working with background, images and date object Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Adding Image, audio and video files to web pages Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
LOGO Introduction to Client-Side Scripting and JavaScript CHAPTER 9 Eastern Mediterranean University School of Computing and Technology Department of Information.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
1 JavaScript
JavaScript Syntax, how to use it in a HTML document
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
COMP403 Web Design JAVA SCRİPTS Tolgay KARANFİLLER.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Pertemuan 5 IT133 Pengembangan Web JavaScript. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting.
HTML FORMS Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan. 1.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
HTML 5 Form elements Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
HTML DOM Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
JavaScript and Ajax (JavaScript Basic) Week 2 Web site:
HTML Links and navigation Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
CGS 3066: Web Programming and Design Spring 2017
Java Script Introduction. Java Script Introduction.
Introduction to Client-Side Scripting and JavaScript
Week 3: Introduction to Javascript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript.
The structure of computer programs
JavaScript an introduction.
WEB PROGRAMMING JavaScript.
T. Jumana Abu Shmais – AOU - Riyadh
CS105 Introduction to Computer Concepts
Tutorial 10: Programming with javascript
Web Programming– UFCFB Lecture 13
Web Programming and Design
CS105 Introduction to Computer Concepts JavaScript
Presentation transcript:

Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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 tag is used to tell the browser that a script follows Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 7

2.1 Internal Scripts The tag is used to embed JavaScript code in HTML documents [JavaScript Statements...] JavaScript can be placed anywhere between and tags two possibilities are the … portion and the … portion Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 8

2.1 Internal Scripts… Using Multiple scripts [JavaScript statements...] [JavaScript statements...] This is another script [JavaScript statements...] Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 9

2.2 External Script We place script in a separate file and include this in HTML code SRC attribute of the is used to include the external JavaScript file in HTML Are useful when you have lengthy scripts Improve the readability Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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 /* */ Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 11

3. JavaScript Conventions… Using Quotes document.write(“ Hello World ”) Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 12

4. Writing JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 13 Start of JS script Writing on webpage HTML code in JS End of JS script

4. Writing JavaScript… Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 14 Out put of the JS code

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 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 16

4.1 Variables in JavaScript… Variable Initialization – var variableName = initialValue – var variableName1 = initialValue1, variableName2 = initialValue2, … Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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: ==, ===, !=, !==,, = Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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… Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 20 Start of JS code User input Writing on browser End of Script

7. JavaScript Function User defined functions Predefined functions Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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] } Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 22

7. JavaScript Function… Calling a function – The syntax of a function call is: functionName([arguments]) Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 23

7. JavaScript Function… Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 24 Start of the function Asks user to enter name Writes name on the webpage Calling a function

7. JavaScript Function… Common events onClick onDblClick onChange onFocus onMouseOver onMouseOut onSubmit onload Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 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 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 26

8. Conditional Statements If statement if (condition) statement if(condition) { statements } If-else statement if(condition) {statement} else {statements} Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 27

8. Conditional Statements… Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 28 Random number is generated User’s Input If condition )*10

8. Conditional Statements… Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 29 On click event text

9. Loops For loop for(var i=1; i<10; i++) { Document.write(“hello world”) } While loop While(condition) { } Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 30

9. Loops Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 31 For loop Do-while loop

9. Loops Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 32 Output of for loop Output of do- while loop

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 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 33

Chapter 11. Beginning HTML, XHTML,CSS, and JavaScript, by Jon Duckett, Wiley Publishing; 2009, ISBN: Chapter 2, Learn JavaScript, by Chuck Easttom, Wordware Publishing; 2002, ISBN Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. References