SlideShare una empresa de Scribd logo
1 de 62
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!");

Más contenido relacionado

La actualidad más candente

Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#
Asim Rais Siddiqui
 

La actualidad más candente (20)

3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Java Script
Java ScriptJava Script
Java Script
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Json
JsonJson
Json
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
Html forms
Html formsHtml forms
Html forms
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#Coding Standards & Best Practices for iOS/C#
Coding Standards & Best Practices for iOS/C#
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Web api
Web apiWeb api
Web api
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
Flexbox and Grid Layout
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid Layout
 

Destacado

The big bang theory - UNIT 2
The big bang theory - UNIT 2The big bang theory - UNIT 2
The big bang theory - UNIT 2
lm092068
 
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup EmpireThe Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
Seh Hui Leong
 
An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5
Event Handler
 
Introduction to JavaScript: Week Two
Introduction to JavaScript: Week TwoIntroduction to JavaScript: Week Two
Introduction to JavaScript: Week Two
Event Handler
 
An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4
Event Handler
 

Destacado (20)

Java script basics
Java script basicsJava script basics
Java script basics
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
Js ppt
Js pptJs ppt
Js ppt
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
Java Script Basics
Java Script BasicsJava Script Basics
Java Script Basics
 
Introduction to Java Script
Introduction to Java ScriptIntroduction to Java Script
Introduction to Java Script
 
The big bang theory - UNIT 2
The big bang theory - UNIT 2The big bang theory - UNIT 2
The big bang theory - UNIT 2
 
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup EmpireThe Big Bang Theory: Nine Steps To Building Your Meetup Empire
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
 
The big bang theory of social recruiting
The big bang theory of social recruitingThe big bang theory of social recruiting
The big bang theory of social recruiting
 
Java Script
Java ScriptJava Script
Java Script
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5An Introduction to JavaScript: Week 5
An Introduction to JavaScript: Week 5
 
8. java script
8. java script8. java script
8. java script
 
Introduction to JavaScript: Week Two
Introduction to JavaScript: Week TwoIntroduction to JavaScript: Week Two
Introduction to JavaScript: Week Two
 
An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 4
 

Similar a Java script -23jan2015

Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
Fermin Galan
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
FIWARE
 

Similar a Java script -23jan2015 (20)

J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
 
ppt 17 18.pptx
ppt 17 18.pptxppt 17 18.pptx
ppt 17 18.pptx
 
J Query Public
J Query PublicJ Query Public
J Query Public
 
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
 
jQuery
jQueryjQuery
jQuery
 
INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMING
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
 
GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
 
Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
Developing Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationDeveloping Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web Application
 
331592291-HTML-and-Cascading style sheet
331592291-HTML-and-Cascading style sheet331592291-HTML-and-Cascading style sheet
331592291-HTML-and-Cascading style sheet
 
VMWorld 2017 Hackathon training: Getting Started with Clarity
VMWorld 2017 Hackathon training: Getting Started with ClarityVMWorld 2017 Hackathon training: Getting Started with Clarity
VMWorld 2017 Hackathon training: Getting Started with Clarity
 
The Principle of Hybrid App.
The Principle of Hybrid App.The Principle of Hybrid App.
The Principle of Hybrid App.
 
Java script tutorial
Java script tutorialJava script tutorial
Java script tutorial
 
mule salesforce
mule salesforcemule salesforce
mule salesforce
 

Más de Sasidhar Kothuru

Web technologies quiz questions - unit1,2
Web technologies quiz questions  - unit1,2Web technologies quiz questions  - unit1,2
Web technologies quiz questions - unit1,2
Sasidhar Kothuru
 

Más de Sasidhar Kothuru (20)

Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
 
Spsl unit1
Spsl   unit1Spsl   unit1
Spsl unit1
 
Spsl II unit
Spsl   II unitSpsl   II unit
Spsl II unit
 
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
 
Servlets
ServletsServlets
Servlets
 
Servers names
Servers namesServers names
Servers names
 
Servers names
Servers namesServers names
Servers names
 
Web Technologies -- Servlets 4 unit slides
Web Technologies -- Servlets   4 unit slidesWeb Technologies -- Servlets   4 unit slides
Web Technologies -- Servlets 4 unit slides
 
Xml quiz 3 unit
Xml quiz   3 unitXml quiz   3 unit
Xml quiz 3 unit
 
Web technologies quiz questions - unit1,2
Web technologies quiz questions  - unit1,2Web technologies quiz questions  - unit1,2
Web technologies quiz questions - unit1,2
 
Web technologies 4th unit quiz
Web technologies 4th unit quizWeb technologies 4th unit quiz
Web technologies 4th unit quiz
 
Xml quiz 3 unit
Xml quiz   3 unitXml quiz   3 unit
Xml quiz 3 unit
 
Web technologies quiz questions - unit1,2
Web technologies quiz questions  - unit1,2Web technologies quiz questions  - unit1,2
Web technologies quiz questions - unit1,2
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
Xml sasidhar
Xml  sasidharXml  sasidhar
Xml sasidhar
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

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!");