SlideShare a Scribd company logo
K.Sasidhar
JavaScript
K.Sasidhar
K.Sasidhar
Introduction to JavaScript
 At First, Scripting Language developed by Sun Micro
Systems & Netscape jointly
 JavaScript was designed to add interactivity to HTML
pages
 JavaScript is a scripting language
 A scripting language is a lightweight programming
language
 JavaScript is usually embedded directly into HTML
pages
 JavaScript is an interpreted language (means that scripts
execute without preliminary compilation)
K.Sasidhar
Importance / facts
 Embedded into HTML
 Browser Dependent
 Interpreted Language
 Loosely Typed Language
 Object-Based Language
 Event-Driven
 Java Script is not java
K.Sasidhar
Importance ………
 JavaScript is multifunctional
i) Enhance HTML Pages
ii) Develop client side applications
iii) creates extensions to a webserver
iv) Provide database connectivity without
using CGI
K.Sasidhar
Web Application Framework
Content
Creation
Graphics
Editor
HTML Editor
Browsers Client
Extensions
Active X
Applets
Scripting
JavaScript
VB Script
Servers Server
Extension
s
Java
script
Database
Extensions
ODBC, JDBC
Security
Content
Management
Search tools
Database Services
K.Sasidhar
JavaScript & HTML
 JavaScript is integrated into HTML with
 <script> and </script> tags.
 Ex:
 <script language = “JavaScript”>
 </script>
K.Sasidhar
First program
 Ex:
 <script language=“JavaScript”>
 {
 Document.write(“Hello to script”);
 }
 </script>
K.Sasidhar
Ex program
 <HTML>
 <HEAD>
 <TITLE>
 JAVASCRIPT PROGRAM TESTING</TITLE>
 <SCRIPT LANGUAGE="JavaScript">
 alert("Hello! everybody");
 </script>
 </head>
 <body>
 testing script
 </body>
 </html>
K.Sasidhar
User Interaction
 <HTML>
 <HEAD><TITLE>
 Dialog Box from a function</TITLE>
 <SCRIPT LANGUAGE="JavaScript">
 function opendoc()
 {
 alert(“dialog called from function");
 }
 </script></head>
 <body><b>Push button test</b>
 <FORM METHOD=“POST”>
 <INPUT TYPE=Button Name=“B1” VALUE=“push”
onClick=“opendoc()”></FORM>
 </body>
 </html>
K.Sasidhar
Identifiers, Keywords
 Variables or methods or objects
 Key words:
 break, if, this, continue, in, time, else,
but, false, new, while, for, null, with,
function and return.
 Literals:
 Integer, Floating, Boolean, String,
Special characters.
K.Sasidhar
Variables
 Variables are used to store the data.
 Ex:
 Var variablename;
 Types: Number, Boolean, String,
Function, Object
 A variable declared inside a function
has local scope.
K.Sasidhar
Global Scope
 Global variables are accessible to all
parts of an application including
functions.
 Global variable is created by initializing
it directly and not using the keyword
var.
 Comments: // or /* ------*/
K.Sasidhar
Functions
 Declaration:
 function displaymessage()
 {
 document.write(“functions demo”);
 }
 A function is declared in the head part of
html.
K.Sasidhar
Operators
 Assignment
 Arithmetic
 Comparison
 Conditional
 String
 Boolean
 Type
 Function
K.Sasidhar
Operators continue…
 Data structure
 Bitwise
K.Sasidhar
Control Structures
 Conditional
 Looping
 With
 Conditional:
if(condition)
{ statements
}
K.Sasidhar
Conditions ……
 if – else
 if(condition)
 {
 Statemetns
 }
 Else
 {
 }
K.Sasidhar
Looping
 for :
 for (initializing exp; condition-exp; loop-exp)
 {
 Statements;
 }
 Ex:
 for(var i=0;i<10;i++)
 {
 document.writeln(i);
 }
K.Sasidhar
for … in
 for .. in loop works with arrays.
 Ex: for (index in arrayName)
 {
 // some code
 }
 index is a variable that we declare prior to
loop, that will automatically populated with
the next index value in array.
K.Sasidhar
Example:
 var myArray= new Array(“rama”, “ravana”);
 var elementIndex;
 for(elementIndex in myArray)
 {
 document. Write(myArray[elementIndex]);
 }
K.Sasidhar
While Loop
 While loop allows to test a condition and
keep on looping while it’s true.
 While loop is more useful when you don’t
know how many you will need to loop.
K.Sasidhar
do-while, break and continue
 break terminates the loop altogether
 continue skips the remaining statements
for the current loop,
K.Sasidhar
Object Model
 Java script is an object based
language.
 It has no inheritance.
 The relation between objects is not of
ancestor descendent but of container.
 When an objects properties or methods
are referenced is used to denoted
ownership.
K.Sasidhar
Java Script Objects &
Corresponding HTML tags
 Window ---
 Frame <frame>
 History ----
 Location ----
 Document <BODY>
 form <FORM>
 Button <Input type = “button”>
 Checkbox < Input type = “checkbox” >
K.Sasidhar
Object Model Hierarchy
Window
history location
text
Text area
form
frameDocument
password
hidden
checkbox
Select
link
Reset
submit
button
anchorimage
radio
Navigator
String
Array
Date
Math
K.Sasidhar
Window object
 Browser runs in a window.
 This is highest level object.
 It contains all other navigator object.
 Two primary methods:
 open() – name of html page, internal name of
window, host features of the window – menu
bar, tool bar, location, directories, document
and status.
 These are properties of window object.
K.Sasidhar
Ex:
 function a()
 {
 var k= window.open(“xyz.html”,
“mywin”,”menubar=yes, toolbar=yes,
location=yes directories=yes,
status=yes”);
}
K.Sasidhar
Properties with objects
 window.status = “this is displayed on
the status bar”
 HISTORY object
 To navigate to back page
 Window.history.back()
 Window.history.forward()
K.Sasidhar
Continue…
 Specific page no
 Use go() method
 Window.history.go(5)
 Location object:
K.Sasidhar
Ex:
 Ex: function evalProtocol
 {
 if(curProtocol == “http:”)
 {
 alert(“from web”);
 else
 if(curProtocol == “file:”)
 alert(“from file”);
 else
 alert(“else where”);
 }
 }
K.Sasidhar
Location object properties
 Href: complete URL
 Protocol: initial element of a URL
 Hostname: Host and domain name or
IP address
 Host : Hostname: Port element of a
URL
 Port: communications port of server
 Pathname: path element of URL
K.Sasidhar
Continue….
 Serach: query definition portion of URL
 Hash : Anchor name of url (begin with #)
 Opening a new URL:
 Window.location=http://www.snist.com/
 Window.location.href = “href://
www.snist.com/”
K.Sasidhar
Document object
 This is important and is responsible for all the
actual content displayed on a given page.
 We can display dynamic HTML pages & all user
interface elements.
 Write() or writeln() method is used to display
content on page.
 This is equivalent of HTML document.
 It is a container for all HTML related objects
associated with <head><body> tags.
K.Sasidhar
Document continue…..
 <BODY
 [BACKGROUND = “backgroundImage”]
 [BGCOLOR = “backgroundColor”]
 [TEXT = “foregroundColor”]
 [LINK = “unfollowedLinkColor”]
 [ALINK = “activatedLinkColor”]
 [VLINK = “followedLinkColor”]
 [onload = “methodName”]
 [onUnload = “methodName”]>
K.Sasidhar
Form Object
 This allows users interactions.
 Gives life to static web pages.
 Properties:
 <FORM
 [NAME=“formName”]
 [ACTION=“ServerURL”]
 [ENCTYPE=“encodingType”]
 [METHOD = “GET|POST”]
 [TARGET = “windowName”]
 [onSubmit = “methodName”]
 </FORM>
K.Sasidhar
Text Object
 Common element to gather data entered by user.
 <INPUT type=“text”
 [Name = “objectname”]
 [Value=“value”]
 [Size=size]
 [MAX.LENGTH = size]
 [onBlur = “methodname”]
 [onChange = “methodname”]
 [onFocus = “methodname”]
 [onSelect = “methodname”]
K.Sasidhar
Text Area Object
 < TEXTAREA
 [Name = “objectName”]
 [ROWS=“numRows”]
 [COLS=“numCols”
 [WRAP=“off | virtual | physical”]
 [onBlur = “methodname”]
 [onChange = “methodname”]
 [onFocus = “methodname”]
 [onSelect = “methodname”]
 </TEXTAREA>
K.Sasidhar
Password object
 <INPUT type=“password”
 [Name = “objectname”]
 [Value=“defaultpassword”]
 [Size=integer]
 Anchor Object:
 <A [HREF = URL ]
 Name = “objectname”
 [TARGET = “windowName”]>
K.Sasidhar
Button
 This is a generic object that we have to
add code for it to be useful.
 Submit button is used to submit form data.
 Reset button is for reset the values of all
controls of a form.
K.Sasidhar
Button properties
<INPUT
TYPE=“button | submit | reset”
[NAME = “objectName”]
[VALUE=“labelText”]
[onClick = “methodName”]
K.Sasidhar
Select Object
 <SELECT>
 [Name = “objectname”]
 [Size=“numberVisible”]
 [MULTIPLE]
 [onBlur = “methodname”]
 [onChange = “methodname”]
 [onFocus = “methodname”]
 <OPTION VALUE = “optionValue”
<[SELECTED]>
K.Sasidhar
Radio Object
 <input>
 TYPE = “radio”
 [NAME = “groupName”]
 [VALUE = “value”][CHECKED]
 [onClick=“methodName”]> [displayText]
K.Sasidhar
BUILT-IN LANGUAGE
Objects
 String
 Date
 Array
 Math
K.Sasidhar
Methods…..
 Length
 CharAt(pos)
 IndexOf (search text[startPos],[endpos])
 Substring(startPos,endPos)
 Big
 Blink
 Fixed
 Fontcolor
 Fontsize
 Small
 Strike
 Sub
 Sup
 toLowerCase
 toUPperCase
K.Sasidhar
Date
 getDate()
 getDay()
 getHours()
 getMinutes()
 getMonth()
 getSeconds()
 getTime()
 getYear()
 getTimeZoneOffset() --- GMT etc..
K.Sasidhar
Set Methods of Date object
 setdate(value)
 setHours(value)
 setMinutes(value)
 setMonth(value)
 setSeconds(value)
 setTime(value)
 setYear(value)
K.Sasidhar
examples
 var today = newDate()
 Result = today.getDate()
 Other formats:
 getFullyear() returns a year in the yyyy
format
 getActualMonth() returns the actual
numeric value for the month
 getCalenderMonth() returns the name of
the month
K.Sasidhar
Date methods continue…..
 getActualDay() returns the actual numeric
value of the day of the week
 getCalenderDay() returns the name of the
day of the week
K.Sasidhar
Mathematical constants
Property Description
E Returns Euler's number (approx. 2.718)
LN2 Returns the natural logarithm of 2 (approx. 0.693)
LN10 Returns the natural logarithm of 10 (approx. 2.302)
LOG2E Returns the base-2 logarithm of E (approx. 1.442)
LOG10E Returns the base-10 logarithm of E (approx. 0.434)
PI Returns PI (approx. 3.14)
SQRT1_2 Returns the square root of 1/2 (approx. 0.707)
SQRT2 Returns the square root of 2 (approx. 1.414)
K.Sasidhar
Math Object
 abs(value) absolute value
 acos(value) arc cosine value in radians
 asin(value) arc sine of value in radians
 atan(value) arc tangent of value in radians
 ceil(value)
 Cos(value) cosine value
 floor(value)
K.Sasidhar
Math continue
 exp(value) Euler’s constant to the power of value
(euler’s constant: 2.718)
 log(value)
 max(value)
 min(value)
 pow(value)
 round(value)
 sin(value)
 sqrt(value)
 tan(value)
K.Sasidhar
Arrays
K.Sasidhar
Arrays
 <html>
 <body>
 <script type="text/javascript">
 var i;
 var mycars = new Array();
 mycars[0] = "Saab";
 mycars[1] = "Volvo";
 mycars[2] = "BMW";
 for (i=0;i<mycars.length;i++)
 {
 document.write(mycars[i] + "<br />");
 }
 </script>
 </body>
 </html>
K.Sasidhar
Join two arrays
 <html>
 <body>
 <p id="demo">Click the button to join three arrays.</p>
 <button onclick="myFunction()">Try it</button>
 <script type="text/javascript">
 function myFunction()
 {
 var hege = ["Cecilie", "Lone"];
 var stale = ["Emil", "Tobias", "Linus"];
 var kai = ["Robin"];
 var children = hege.concat(stale,kai);
 var x=document.getElementById("demo");
 x.innerHTML=children;
 }
 </script>
 </body>
 </html>
K.Sasidhar
Remove the last element
 <!DOCTYPE html>
 <html>
 <body>
 <p id="demo">Click the button to remove the last array element.</p>
 <button onclick="myFunction()">Try it</button>
 <script type="text/javascript">
 var fruits = ["Banana", "Orange", "Apple", "Mango"];
 function myFunction()
 {
 fruits.pop();
 var x=document.getElementById("demo");
 x.innerHTML=fruits;
 }
 </script>
 </body>
 </html>
K.Sasidhar
Creating custom objects
 function object (parameter1, parameter2,…)
 {
 this.property1=parameter1
 this.property2=parameter2
 this.method1=function1
 this.method2=function2
 }
K.Sasidhar
Instantiating objects
 new operator is used for instantiating objects
 objectInstance= objectType(parameter1,
2,3,……)
 Ex: creating a book object using the
following code
 dbBook=new book(“beginning javascript”,
“paul wilton”, “Rs.400”, “ 1000”);
K.Sasidhar
Exception Handling
 The try...catch statement allows you to test a
block of code for errors. The try block contains
the code to be run, and the catch block contains
the code to be executed if an error occurs.
 try
  {
  //Run some code here
  }
catch(err)
  {
  //Handle errors here
  }
K.Sasidhar
The Throw Statement
 The throw statement allows you to create an
exception. If you use this statement together
with the try...catch statement, you can
control program flow and generate accurate
error messages.
 Syntax: throw exception
K.Sasidhar
Example
 The example below determines the value of
a variable called x. If the value of x is
higher than 10, lower than 5, or not a
number, then throw an error. The error is
then caught by the catch argument and the
proper error message is displayed:
K.Sasidhar
JavaScript facts
 JavaScript is Case Sensitive
 A function named "myfunction" is not the same as
"myFunction" and a variable named "myVar" is not the
same as "myvar".
 JavaScript is case sensitive - therefore watch your
capitalization closely when you create or call variables,
objects and functions.
 White Space:
 JavaScript ignores extra spaces. You can add white
space to your script to make it more readable. The
following lines are equivalent:
 var name="Hege";
var name = "Hege";

K.Sasidhar
Break up a Code Line
 You can break up a code line within a text
string with a backslash. The example below
will be displayed properly:
 document.write("Hello 
World!");
 However, you cannot break up a code line
like this:
 document.write 
("Hello World!");

More Related Content

PPTX
html-css
Dhirendra Chauhan
 
PPTX
Complete Lecture on Css presentation
Salman Memon
 
PPTX
Dart programming language
Aniruddha Chakrabarti
 
PPT
Javascript
mussawir20
 
PPTX
Html5 Basic Structure
Niket Chandrawanshi
 
PDF
Intro to HTML and CSS basics
Eliran Eliassy
 
PPTX
JSON: The Basics
Jeff Fox
 
PPT
Cascading Style Sheets (CSS) help
casestudyhelp
 
Complete Lecture on Css presentation
Salman Memon
 
Dart programming language
Aniruddha Chakrabarti
 
Javascript
mussawir20
 
Html5 Basic Structure
Niket Chandrawanshi
 
Intro to HTML and CSS basics
Eliran Eliassy
 
JSON: The Basics
Jeff Fox
 
Cascading Style Sheets (CSS) help
casestudyhelp
 

What's hot (20)

PDF
JavaScript - Chapter 11 - Events
WebStackAcademy
 
PPT
Introduction to CSS
Amit Tyagi
 
PPTX
css.ppt
bhasula
 
PPT
CSS for Beginners
Amit Kumar Singh
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PPSX
Javascript variables and datatypes
Varun C M
 
ODP
Introduction of Html/css/js
Knoldus Inc.
 
PPT
CSS Basics
WordPress Memphis
 
PPTX
HTML frames and HTML forms
Nadine Cruz
 
PPTX
Css selectors
Parth Trivedi
 
PPTX
Java Script
husbancom
 
PDF
HTML and CSS crash course!
Ana Cidre
 
PPTX
Html, CSS & Web Designing
Leslie Steele
 
PDF
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
Edureka!
 
PDF
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
KEY
CSS and CSS3
Robyn Overstreet
 
PPT
Box Model
Amit Kumar Singh
 
PPT
Introduction to Javascript
Amit Tyagi
 
PPTX
Introduction to CSS
Folasade Adedeji
 
JavaScript - Chapter 11 - Events
WebStackAcademy
 
Introduction to CSS
Amit Tyagi
 
css.ppt
bhasula
 
CSS for Beginners
Amit Kumar Singh
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Javascript variables and datatypes
Varun C M
 
Introduction of Html/css/js
Knoldus Inc.
 
CSS Basics
WordPress Memphis
 
HTML frames and HTML forms
Nadine Cruz
 
Css selectors
Parth Trivedi
 
Java Script
husbancom
 
HTML and CSS crash course!
Ana Cidre
 
Html, CSS & Web Designing
Leslie Steele
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
Edureka!
 
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
CSS and CSS3
Robyn Overstreet
 
Box Model
Amit Kumar Singh
 
Introduction to Javascript
Amit Tyagi
 
Introduction to CSS
Folasade Adedeji
 
Ad

Viewers also liked (20)

PPTX
Java script basics
Shrivardhan Limbkar
 
PPTX
Java script
Jay Patel
 
PPTX
Java script
Sadeek Mohammed
 
PPT
Java script
Fajar Baskoro
 
PDF
Fundamental JavaScript [UTC, March 2014]
Aaron Gustafson
 
PDF
Introduction to JavaScript
Bryan Basham
 
PPT
Javascript
guest03a6e6
 
PPT
Js ppt
Rakhi Thota
 
PPT
JavaScript - An Introduction
Manvendra Singh
 
PDF
JavaScript Programming
Sehwan Noh
 
PDF
Javascript Best Practices
Christian Heilmann
 
PPT
Java Script Basics
Ravi Kumar Hamsa
 
PPTX
Introduction to Java Script
Vijay Kumar Verma
 
PPTX
The big bang theory - UNIT 2
lm092068
 
PDF
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
Seh Hui Leong
 
PPTX
The big bang theory of social recruiting
FastCollab
 
PPT
Java Script
siddaram
 
PPT
JAVA SCRIPT
Go4Guru
 
PDF
An Introduction to JavaScript: Week 5
Event Handler
 
Java script basics
Shrivardhan Limbkar
 
Java script
Jay Patel
 
Java script
Sadeek Mohammed
 
Java script
Fajar Baskoro
 
Fundamental JavaScript [UTC, March 2014]
Aaron Gustafson
 
Introduction to JavaScript
Bryan Basham
 
Javascript
guest03a6e6
 
Js ppt
Rakhi Thota
 
JavaScript - An Introduction
Manvendra Singh
 
JavaScript Programming
Sehwan Noh
 
Javascript Best Practices
Christian Heilmann
 
Java Script Basics
Ravi Kumar Hamsa
 
Introduction to Java Script
Vijay Kumar Verma
 
The big bang theory - UNIT 2
lm092068
 
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
Seh Hui Leong
 
The big bang theory of social recruiting
FastCollab
 
Java Script
siddaram
 
JAVA SCRIPT
Go4Guru
 
An Introduction to JavaScript: Week 5
Event Handler
 
Ad

Similar to Java script -23jan2015 (20)

PPTX
ppt 17 18.pptx
DrRavneetSingh
 
PPTX
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
Nuzhat Memon
 
PPTX
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
PDF
Training javascript 2012 hcmut
University of Technology
 
PPTX
Chapter 3 INTRODUCTION TO JAVASCRIPT S.pptx
KelemAlebachew
 
PPTX
JAVASRIPT and PHP Basics# Unit 2 Webdesign
NitinShelake4
 
DOC
javscript
rcc1964
 
PPTX
Javascript
D V BHASKAR REDDY
 
PPTX
BITM3730Week6.pptx
MattMarino13
 
PDF
JavaScript Getting Started
Hazem Hagrass
 
PDF
Iwt note(module 2)
SANTOSH RATH
 
PDF
Lecture7
Majid Taghiloo
 
PDF
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
AAFREEN SHAIKH
 
PPT
Scripting languages
teach4uin
 
PPT
Javascript sivasoft
ch samaram
 
PPTX
javaScript and jQuery
Mehrab Hossain
 
PPT
Java script
Soham Sengupta
 
PPTX
BITM3730 10-4.pptx
MattMarino13
 
PPTX
BITM3730 10-3.pptx
MattMarino13
 
PPTX
CSC PPT 12.pptx
DrRavneetSingh
 
ppt 17 18.pptx
DrRavneetSingh
 
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
Nuzhat Memon
 
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
Training javascript 2012 hcmut
University of Technology
 
Chapter 3 INTRODUCTION TO JAVASCRIPT S.pptx
KelemAlebachew
 
JAVASRIPT and PHP Basics# Unit 2 Webdesign
NitinShelake4
 
javscript
rcc1964
 
Javascript
D V BHASKAR REDDY
 
BITM3730Week6.pptx
MattMarino13
 
JavaScript Getting Started
Hazem Hagrass
 
Iwt note(module 2)
SANTOSH RATH
 
Lecture7
Majid Taghiloo
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
AAFREEN SHAIKH
 
Scripting languages
teach4uin
 
Javascript sivasoft
ch samaram
 
javaScript and jQuery
Mehrab Hossain
 
Java script
Soham Sengupta
 
BITM3730 10-4.pptx
MattMarino13
 
BITM3730 10-3.pptx
MattMarino13
 
CSC PPT 12.pptx
DrRavneetSingh
 

More from Sasidhar Kothuru (20)

PPT
Spsl vi unit final
Sasidhar Kothuru
 
PPT
Spsl iv unit final
Sasidhar Kothuru
 
PPT
Spsl v unit - final
Sasidhar Kothuru
 
PPT
Spsl iv unit final
Sasidhar Kothuru
 
PPT
Spsl v unit - final
Sasidhar Kothuru
 
PPT
Spsl by sasidhar 3 unit
Sasidhar Kothuru
 
PPT
Spsl unit1
Sasidhar Kothuru
 
PPT
Spsl II unit
Sasidhar Kothuru
 
PPT
Jdbc sasidhar
Sasidhar Kothuru
 
PPT
Servlets
Sasidhar Kothuru
 
PPT
Servers names
Sasidhar Kothuru
 
PPT
Servers names
Sasidhar Kothuru
 
PPT
Web Technologies -- Servlets 4 unit slides
Sasidhar Kothuru
 
DOC
Xml quiz 3 unit
Sasidhar Kothuru
 
DOC
Web technologies quiz questions - unit1,2
Sasidhar Kothuru
 
DOC
Web technologies 4th unit quiz
Sasidhar Kothuru
 
DOC
Xml quiz 3 unit
Sasidhar Kothuru
 
DOC
Web technologies quiz questions - unit1,2
Sasidhar Kothuru
 
PPT
Jsp sasidhar
Sasidhar Kothuru
 
PPT
Xml sasidhar
Sasidhar Kothuru
 
Spsl vi unit final
Sasidhar Kothuru
 
Spsl iv unit final
Sasidhar Kothuru
 
Spsl v unit - final
Sasidhar Kothuru
 
Spsl iv unit final
Sasidhar Kothuru
 
Spsl v unit - final
Sasidhar Kothuru
 
Spsl by sasidhar 3 unit
Sasidhar Kothuru
 
Spsl unit1
Sasidhar Kothuru
 
Spsl II unit
Sasidhar Kothuru
 
Jdbc sasidhar
Sasidhar Kothuru
 
Servers names
Sasidhar Kothuru
 
Servers names
Sasidhar Kothuru
 
Web Technologies -- Servlets 4 unit slides
Sasidhar Kothuru
 
Xml quiz 3 unit
Sasidhar Kothuru
 
Web technologies quiz questions - unit1,2
Sasidhar Kothuru
 
Web technologies 4th unit quiz
Sasidhar Kothuru
 
Xml quiz 3 unit
Sasidhar Kothuru
 
Web technologies quiz questions - unit1,2
Sasidhar Kothuru
 
Jsp sasidhar
Sasidhar Kothuru
 
Xml sasidhar
Sasidhar Kothuru
 

Recently uploaded (20)

PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Software Development Company | KodekX
KodekX
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
This slide provides an overview Technology
mineshkharadi333
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 

Java script -23jan2015

  • 2. K.Sasidhar Introduction to JavaScript  At First, Scripting Language developed by Sun Micro Systems & Netscape jointly  JavaScript was designed to add interactivity to HTML pages  JavaScript is a scripting language  A scripting language is a lightweight programming language  JavaScript is usually embedded directly into HTML pages  JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
  • 3. K.Sasidhar Importance / facts  Embedded into HTML  Browser Dependent  Interpreted Language  Loosely Typed Language  Object-Based Language  Event-Driven  Java Script is not java
  • 4. K.Sasidhar Importance ………  JavaScript is multifunctional i) Enhance HTML Pages ii) Develop client side applications iii) creates extensions to a webserver iv) Provide database connectivity without using CGI
  • 5. K.Sasidhar Web Application Framework Content Creation Graphics Editor HTML Editor Browsers Client Extensions Active X Applets Scripting JavaScript VB Script Servers Server Extension s Java script Database Extensions ODBC, JDBC Security Content Management Search tools Database Services
  • 6. K.Sasidhar JavaScript & HTML  JavaScript is integrated into HTML with  <script> and </script> tags.  Ex:  <script language = “JavaScript”>  </script>
  • 7. K.Sasidhar First program  Ex:  <script language=“JavaScript”>  {  Document.write(“Hello to script”);  }  </script>
  • 8. K.Sasidhar Ex program  <HTML>  <HEAD>  <TITLE>  JAVASCRIPT PROGRAM TESTING</TITLE>  <SCRIPT LANGUAGE="JavaScript">  alert("Hello! everybody");  </script>  </head>  <body>  testing script  </body>  </html>
  • 9. K.Sasidhar User Interaction  <HTML>  <HEAD><TITLE>  Dialog Box from a function</TITLE>  <SCRIPT LANGUAGE="JavaScript">  function opendoc()  {  alert(“dialog called from function");  }  </script></head>  <body><b>Push button test</b>  <FORM METHOD=“POST”>  <INPUT TYPE=Button Name=“B1” VALUE=“push” onClick=“opendoc()”></FORM>  </body>  </html>
  • 10. K.Sasidhar Identifiers, Keywords  Variables or methods or objects  Key words:  break, if, this, continue, in, time, else, but, false, new, while, for, null, with, function and return.  Literals:  Integer, Floating, Boolean, String, Special characters.
  • 11. K.Sasidhar Variables  Variables are used to store the data.  Ex:  Var variablename;  Types: Number, Boolean, String, Function, Object  A variable declared inside a function has local scope.
  • 12. K.Sasidhar Global Scope  Global variables are accessible to all parts of an application including functions.  Global variable is created by initializing it directly and not using the keyword var.  Comments: // or /* ------*/
  • 13. K.Sasidhar Functions  Declaration:  function displaymessage()  {  document.write(“functions demo”);  }  A function is declared in the head part of html.
  • 14. K.Sasidhar Operators  Assignment  Arithmetic  Comparison  Conditional  String  Boolean  Type  Function
  • 16. K.Sasidhar Control Structures  Conditional  Looping  With  Conditional: if(condition) { statements }
  • 17. K.Sasidhar Conditions ……  if – else  if(condition)  {  Statemetns  }  Else  {  }
  • 18. K.Sasidhar Looping  for :  for (initializing exp; condition-exp; loop-exp)  {  Statements;  }  Ex:  for(var i=0;i<10;i++)  {  document.writeln(i);  }
  • 19. K.Sasidhar for … in  for .. in loop works with arrays.  Ex: for (index in arrayName)  {  // some code  }  index is a variable that we declare prior to loop, that will automatically populated with the next index value in array.
  • 20. K.Sasidhar Example:  var myArray= new Array(“rama”, “ravana”);  var elementIndex;  for(elementIndex in myArray)  {  document. Write(myArray[elementIndex]);  }
  • 21. K.Sasidhar While Loop  While loop allows to test a condition and keep on looping while it’s true.  While loop is more useful when you don’t know how many you will need to loop.
  • 22. K.Sasidhar do-while, break and continue  break terminates the loop altogether  continue skips the remaining statements for the current loop,
  • 23. K.Sasidhar Object Model  Java script is an object based language.  It has no inheritance.  The relation between objects is not of ancestor descendent but of container.  When an objects properties or methods are referenced is used to denoted ownership.
  • 24. K.Sasidhar Java Script Objects & Corresponding HTML tags  Window ---  Frame <frame>  History ----  Location ----  Document <BODY>  form <FORM>  Button <Input type = “button”>  Checkbox < Input type = “checkbox” >
  • 25. K.Sasidhar Object Model Hierarchy Window history location text Text area form frameDocument password hidden checkbox Select link Reset submit button anchorimage radio Navigator String Array Date Math
  • 26. K.Sasidhar Window object  Browser runs in a window.  This is highest level object.  It contains all other navigator object.  Two primary methods:  open() – name of html page, internal name of window, host features of the window – menu bar, tool bar, location, directories, document and status.  These are properties of window object.
  • 27. K.Sasidhar Ex:  function a()  {  var k= window.open(“xyz.html”, “mywin”,”menubar=yes, toolbar=yes, location=yes directories=yes, status=yes”); }
  • 28. K.Sasidhar Properties with objects  window.status = “this is displayed on the status bar”  HISTORY object  To navigate to back page  Window.history.back()  Window.history.forward()
  • 29. K.Sasidhar Continue…  Specific page no  Use go() method  Window.history.go(5)  Location object:
  • 30. K.Sasidhar Ex:  Ex: function evalProtocol  {  if(curProtocol == “http:”)  {  alert(“from web”);  else  if(curProtocol == “file:”)  alert(“from file”);  else  alert(“else where”);  }  }
  • 31. K.Sasidhar Location object properties  Href: complete URL  Protocol: initial element of a URL  Hostname: Host and domain name or IP address  Host : Hostname: Port element of a URL  Port: communications port of server  Pathname: path element of URL
  • 32. K.Sasidhar Continue….  Serach: query definition portion of URL  Hash : Anchor name of url (begin with #)  Opening a new URL:  Window.location=http://www.snist.com/  Window.location.href = “href:// www.snist.com/”
  • 33. K.Sasidhar Document object  This is important and is responsible for all the actual content displayed on a given page.  We can display dynamic HTML pages & all user interface elements.  Write() or writeln() method is used to display content on page.  This is equivalent of HTML document.  It is a container for all HTML related objects associated with <head><body> tags.
  • 34. K.Sasidhar Document continue…..  <BODY  [BACKGROUND = “backgroundImage”]  [BGCOLOR = “backgroundColor”]  [TEXT = “foregroundColor”]  [LINK = “unfollowedLinkColor”]  [ALINK = “activatedLinkColor”]  [VLINK = “followedLinkColor”]  [onload = “methodName”]  [onUnload = “methodName”]>
  • 35. K.Sasidhar Form Object  This allows users interactions.  Gives life to static web pages.  Properties:  <FORM  [NAME=“formName”]  [ACTION=“ServerURL”]  [ENCTYPE=“encodingType”]  [METHOD = “GET|POST”]  [TARGET = “windowName”]  [onSubmit = “methodName”]  </FORM>
  • 36. K.Sasidhar Text Object  Common element to gather data entered by user.  <INPUT type=“text”  [Name = “objectname”]  [Value=“value”]  [Size=size]  [MAX.LENGTH = size]  [onBlur = “methodname”]  [onChange = “methodname”]  [onFocus = “methodname”]  [onSelect = “methodname”]
  • 37. K.Sasidhar Text Area Object  < TEXTAREA  [Name = “objectName”]  [ROWS=“numRows”]  [COLS=“numCols”  [WRAP=“off | virtual | physical”]  [onBlur = “methodname”]  [onChange = “methodname”]  [onFocus = “methodname”]  [onSelect = “methodname”]  </TEXTAREA>
  • 38. K.Sasidhar Password object  <INPUT type=“password”  [Name = “objectname”]  [Value=“defaultpassword”]  [Size=integer]  Anchor Object:  <A [HREF = URL ]  Name = “objectname”  [TARGET = “windowName”]>
  • 39. K.Sasidhar Button  This is a generic object that we have to add code for it to be useful.  Submit button is used to submit form data.  Reset button is for reset the values of all controls of a form.
  • 40. K.Sasidhar Button properties <INPUT TYPE=“button | submit | reset” [NAME = “objectName”] [VALUE=“labelText”] [onClick = “methodName”]
  • 41. K.Sasidhar Select Object  <SELECT>  [Name = “objectname”]  [Size=“numberVisible”]  [MULTIPLE]  [onBlur = “methodname”]  [onChange = “methodname”]  [onFocus = “methodname”]  <OPTION VALUE = “optionValue” <[SELECTED]>
  • 42. K.Sasidhar Radio Object  <input>  TYPE = “radio”  [NAME = “groupName”]  [VALUE = “value”][CHECKED]  [onClick=“methodName”]> [displayText]
  • 44. K.Sasidhar Methods…..  Length  CharAt(pos)  IndexOf (search text[startPos],[endpos])  Substring(startPos,endPos)  Big  Blink  Fixed  Fontcolor  Fontsize  Small  Strike  Sub  Sup  toLowerCase  toUPperCase
  • 45. K.Sasidhar Date  getDate()  getDay()  getHours()  getMinutes()  getMonth()  getSeconds()  getTime()  getYear()  getTimeZoneOffset() --- GMT etc..
  • 46. K.Sasidhar Set Methods of Date object  setdate(value)  setHours(value)  setMinutes(value)  setMonth(value)  setSeconds(value)  setTime(value)  setYear(value)
  • 47. K.Sasidhar examples  var today = newDate()  Result = today.getDate()  Other formats:  getFullyear() returns a year in the yyyy format  getActualMonth() returns the actual numeric value for the month  getCalenderMonth() returns the name of the month
  • 48. K.Sasidhar Date methods continue…..  getActualDay() returns the actual numeric value of the day of the week  getCalenderDay() returns the name of the day of the week
  • 49. K.Sasidhar Mathematical constants Property Description E Returns Euler's number (approx. 2.718) LN2 Returns the natural logarithm of 2 (approx. 0.693) LN10 Returns the natural logarithm of 10 (approx. 2.302) LOG2E Returns the base-2 logarithm of E (approx. 1.442) LOG10E Returns the base-10 logarithm of E (approx. 0.434) PI Returns PI (approx. 3.14) SQRT1_2 Returns the square root of 1/2 (approx. 0.707) SQRT2 Returns the square root of 2 (approx. 1.414)
  • 50. K.Sasidhar Math Object  abs(value) absolute value  acos(value) arc cosine value in radians  asin(value) arc sine of value in radians  atan(value) arc tangent of value in radians  ceil(value)  Cos(value) cosine value  floor(value)
  • 51. K.Sasidhar Math continue  exp(value) Euler’s constant to the power of value (euler’s constant: 2.718)  log(value)  max(value)  min(value)  pow(value)  round(value)  sin(value)  sqrt(value)  tan(value)
  • 53. K.Sasidhar Arrays  <html>  <body>  <script type="text/javascript">  var i;  var mycars = new Array();  mycars[0] = "Saab";  mycars[1] = "Volvo";  mycars[2] = "BMW";  for (i=0;i<mycars.length;i++)  {  document.write(mycars[i] + "<br />");  }  </script>  </body>  </html>
  • 54. K.Sasidhar Join two arrays  <html>  <body>  <p id="demo">Click the button to join three arrays.</p>  <button onclick="myFunction()">Try it</button>  <script type="text/javascript">  function myFunction()  {  var hege = ["Cecilie", "Lone"];  var stale = ["Emil", "Tobias", "Linus"];  var kai = ["Robin"];  var children = hege.concat(stale,kai);  var x=document.getElementById("demo");  x.innerHTML=children;  }  </script>  </body>  </html>
  • 55. K.Sasidhar Remove the last element  <!DOCTYPE html>  <html>  <body>  <p id="demo">Click the button to remove the last array element.</p>  <button onclick="myFunction()">Try it</button>  <script type="text/javascript">  var fruits = ["Banana", "Orange", "Apple", "Mango"];  function myFunction()  {  fruits.pop();  var x=document.getElementById("demo");  x.innerHTML=fruits;  }  </script>  </body>  </html>
  • 56. K.Sasidhar Creating custom objects  function object (parameter1, parameter2,…)  {  this.property1=parameter1  this.property2=parameter2  this.method1=function1  this.method2=function2  }
  • 57. K.Sasidhar Instantiating objects  new operator is used for instantiating objects  objectInstance= objectType(parameter1, 2,3,……)  Ex: creating a book object using the following code  dbBook=new book(“beginning javascript”, “paul wilton”, “Rs.400”, “ 1000”);
  • 58. K.Sasidhar Exception Handling  The try...catch statement allows you to test a block of code for errors. The try block contains the code to be run, and the catch block contains the code to be executed if an error occurs.  try   {   //Run some code here   } catch(err)   {   //Handle errors here   }
  • 59. K.Sasidhar The Throw Statement  The throw statement allows you to create an exception. If you use this statement together with the try...catch statement, you can control program flow and generate accurate error messages.  Syntax: throw exception
  • 60. K.Sasidhar Example  The example below determines the value of a variable called x. If the value of x is higher than 10, lower than 5, or not a number, then throw an error. The error is then caught by the catch argument and the proper error message is displayed:
  • 61. K.Sasidhar JavaScript facts  JavaScript is Case Sensitive  A function named "myfunction" is not the same as "myFunction" and a variable named "myVar" is not the same as "myvar".  JavaScript is case sensitive - therefore watch your capitalization closely when you create or call variables, objects and functions.  White Space:  JavaScript ignores extra spaces. You can add white space to your script to make it more readable. The following lines are equivalent:  var name="Hege"; var name = "Hege"; 
  • 62. K.Sasidhar Break up a Code Line  You can break up a code line within a text string with a backslash. The example below will be displayed properly:  document.write("Hello World!");  However, you cannot break up a code line like this:  document.write ("Hello World!");