Java Script Dvijesh Bhatt. Web Page HTML defines Web sites content through semantic tags (headings, paragraphs, lists, …). CSS defines 'rules' or 'styles'

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Intro to JavaScript. JavaScript History Client (generally browser-side) language invented at Netscape under the name LiveScript around 1995 Netscape wanted.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
Introduction to scripting
Javascript and the Web Whys and Hows of Javascript.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Scripting Languages.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
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.
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.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Introduction to JavaScript Gordon Tian
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
1 JavaScript
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
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.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 JavaScript in Context. Server-Side Programming.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Javascript Intro Instructor: Shalen Malabon. Lesson Plan Core Javascript Syntax Types and Objects Functions DOM Event Handling Debugging Javascript Smarter.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
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.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
JavaScript Tutorial First lecture 19/2/2016. Javascript is a dynamic computer programming language. It is lightweight and most commonly used as a part.
Javascript Prof. Wenwen Li School of Geographical Sciences and Urban Planning 5644 Coor Hall
CGS 3066: Web Programming and Design Spring 2017
Build in Objects In JavaScript, almost "everything" is an object.
>> Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
Scope, Objects, Strings, Numbers
Introduction to Scripting
JavaScript Syntax and Semantics
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript.
JavaScript an introduction.
WEB PROGRAMMING JavaScript.
PHP.
Functions, Regular expressions and Events
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

Java Script Dvijesh Bhatt

Web Page HTML defines Web sites content through semantic tags (headings, paragraphs, lists, …). CSS defines 'rules' or 'styles' for presenting every aspect of an HTML document Font (family, size, color, weight, etc.) Background (color, image, position, repeat) Position and layout (of any object on the page) JavaScript defines dynamic behavior Programming logic for interaction with the user, to handle events, etc.

Java Scripts JavaScript is a front-end scripting language developed by Netscape for dynamic content Lightweight, but with limited capabilities Can be used as object-oriented language Client-side technology Embedded in your HTML page Interpreted by the Web browser Simple and flexible Powerful to manipulate the DOM

What Java Script can do? Can handle events Can read and write HTML elements and modify the DOM tree Can validate form data Can access / modify browser cookies Can detect the user’s browser and OS Can be used as object-oriented language Can handle exceptions Can perform asynchronous server calls (AJAX) Slider kind of behaviour in web pages

Use of Java Scripts Internal declaration …. External Declaration

Alert box Alert() : will display the alert box.(Pop-up) i.e = alert(“Hello world”); Some of the character will use in alert box \n : New line \t : Horizontal Tab \r : Carriage Return \\ : Use backslash in text \” : Use double quote in text \’ : Use single quote in text

Write To write any thing on page we use write() i.e. documents.write(“Hello World”); documents.write(“ Hello World ”); documents.write(“ \ ” Hello World ” \ ”); documents.writeln(“Hello World”); document.write(“ Nirma Uni ”);

prompt Which allows user to input a value that the script can use. var name; name = window.prompt("Hello"); document.write("Welcome " + name + " for visiting site");

Mathematical operation +, -, *, /, % Precedence Equality operators i.e. =, != Relational operators i.e. >, =, <=

Date var now = Date(); getHours(); getDay getDate parse : Parses a date string and returns the number of milliseconds since midnight of January 1, 1970

Variable var x; // Now x is undefined var x = 5; // Now x is a Number var x = "John"; // Now x is a String var answer="It's alright"; var answer="He is called 'Johnny'"; var answer='He is called "Johnny"'; var x1=34.00; //Written with decimals var x2=34; //Written without decimals

Continue var carname=new String; var x= new Number; var y= new Boolean; var cars= new Array; var person= new Object; var person={ firstname : "John", lastname : "Doe", id : 5566 }; Name = person.firsname ; //person[“firstname”]

Continue var lastName = "Doe", age = 30, job = "carpenter"; typeof "John" // Returns string typeof 3.14 // Returns number typeof false // Returns boolean typeof [1,2,3,4] // Returns object typeof {name:'John', age:34} // Returns object

Array var cars=new Array(); cars[0]="Saab"; cars[1]="Volvo"; cars[2]="BMW"; var cars=new Array("Saab","Volvo","BMW"); var cars=["Saab","Volvo","BMW"];

Objects Objects are just a data, with added properties and methods. Almost "everything" in JavaScript are treated as objects. Dates, Arrays, Strings, Functions.... You can make your own objects as well i.e. var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};

Strings var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var sln = txt.length; var x = "John"; var y = new String("John"); typeof x // returns String typeof y // returns Object

Functions of Strings length search indexof slice() // (7,12) (-12,-6) (7) substring() substr() // (7,6) replace() toUpperCase() toLowerCase() concat() charAt() charCodeAt() var txt = "a,b,c,d,e" // String txt.split(","); // Split on commas txt.split(" "); // Split on spaces txt.split("|"); // Split on pipe

Number and functions Precision: Integers (numbers without a period or exponent notation) are considered accurate up to 15 digits. The maximum number of decimals is 17, but floating point arithmetic is not always 100% accurate: Infinity (or -Infinity) is the value JavaScript will return if you calculate a number outside the largest possible number. var x = 123; var y = new Number(123); typeof x; // returns number typeof y; // returns object

Continue It will convert string in to integer. N1 = parseInt(firstnum); N1 = parseFloat(firstnum); tostring(); toExponential() toFixed() toPrecision() Number() valueOf()

Math Math.random(); Math.min(x,y,z); Math.max(x,y,z); Math.round(x); Math.ceil(x); Math.floor(x); abs(x); pow(x,y); sqrt(x);

Array var person = ["John", "Doe", 46]; var cars = new Array("Saab", "Volvo", "BMW"); var car = new Array(40); car.length(); car.sort(); valueof(); tostring(); join(“*”); splice(2, 0, “Maruti", “Honda");

Condition if (condition) { code to be executed if condition is true } else { code to be executed if condition is not true }

Switch switch(n) { case 1: execute code block 1 break; case 2: execute code block 2 break; default: code to be executed if n is different from case 1 and 2 }

Loops while (condition) { code block to be executed } do { code block to be executed } while (condition);

Continue for (statement 1; statement 2; statement 3) { the code block to be executed } var person={fname:"John",lname:"Doe",age:25}; for (x in person) { txt=txt + person[x]; }

Functions A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses (). Function names can contain letters, digits, underscores, and dollar signs (same rules as variables). The parentheses may include parameter names separated by commas: (parameter1, parameter2,...) The code to be executed, by the function, is placed inside curly brackets: {}

Continue Invoke the fuction var x = myfunction(4,3);

Finding the HTML elements document.getElementById()Find an element by element id document.getElementsByTagName()Find elements by tag name document.getElementsByClassName()Find elements by class name

Change elements and attributes of HTML element.innerHTML=Change the inner HTML of an element element.attribute=Change the attribute of an HTML element element.setAttribute(attribute,value)Change the attribute of an HTML element element.style.property=Change the style of an HTML element

Regular Expression A regular expression can be written in either of two ways: var patt = new RegExp(pattern,modifiers); Or var patt = /pattern/modifiers; pattern specifies the pattern of an expression modifiers specify if a search should be global, case- sensitive, etc.

Modifiers Description i Perform case-insensitive matching g Perform a global match (find all matches rather than stopping after the first match) m Perform multiline matching

Brackets ExpressionDiscreption [A-Z]Find any character between the brackets [^A-Z]Find any character NOT between the brackets [0-9]Find any digit between the brackets [^0-9]Find any digit NOT between the brackets (X|Y)Find any of the alternatives specified

Meta Character Description.Find a single character, except newline or line terminator $End of line or multiple lines ^Beginning of the lines \wFind the Word Character \WFind the non-word Charcter \sFind a whitespace character \SFind a non-whitespace character \dFind Digit only text \DFind non-digit text \bFind a match at the beginning/end of a word \BFind a match not at the beginning/end of a word