SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
Java Script
• It is a client side scripting Language used to
validate data.
• It is embedded in HTML document.
• The <SCRIPT> tag is used to include scripts in an
HTML page.
• JavaScript was developed by Brendan Eich.
• It is supported by almost all web browsers.
• It follows exact the same syntax of C++.
• It ignores spaces, tabs, and newlines that appear in
JavaScript programs.
• JavaScript is a case-sensitive language.
Java Script
<SCRIPT> Tag
• The <SCRIPT> tag is used to
include(embed) script in an HTML page.
• The Language attribute of <SCRIPT> tag
specifies the type of scripting language
used.
Example:-
<SCRIPT Language=”JavaScript”>
</SCRIPT>
Output / input Functions
Output Function
• The document.write ( ) function
• The function document.write which writes a
string into our HTML document.
<html>
<body>
<script language="javascript" >
document.write("Welcome to JavaScript") ;
</script>
</body>
</html>
Output / input Functions
Input Function
• The prompt( message ) function
• The function prompt which takes a string from
keyboard to HTML document.
<script language=“JavaScript">
n=prompt("Enter your Name");
document.write(n);
</script>
Creating functions in JavaScript
• A function is a self-contained unit of a program
that perform a specific task.
• It is an independent part of a program which
is executed when it is called.
• Functions can be placed in the < HEAD> Tag of
<HTML> Tag.
• A function in JavaScript does not have
return type
• A function can be called using its name
such as, print( ).
Creating functions in JavaScript
Defining a function
• Functions must be declared before they are used.
• A function is defined using the function
keyword.
• The function statements are enclosed in curly
brace {} .
• Once a function is defined it can be called many
times. .
A function can be called using its name such as, print( ).
Data types in JavaScript
• Data type specifies the type of data and the
operations that can be performed on the data.
• Data types in JavaScript is classified into two
primitive data type and composite data type.
Primitive data types
The three primitive data types in JavaScript are
Number, String and Boolean.
Number:-They include integers and floating point
numbers.
Strings:-A string is a combination of characters,
numbers or symbols enclosed within double
quotes.
Boolean:-A Boolean data can be either True or
False.
Variables in JavaScript
• A variable is a data type whose value changes
during program execution.
• Variables in JavaScript are declared using
the var keyword.
Example:- var a;
Declares a variable a.
Example:- var msg=”Hello”;
Note:-JavaScript determines the typeof variable
only when assigning a value.
Variables in JavaScript
Example:-A web page to find the sum of two numbers
<HTML><HEAD>
<TITLE>JAVASCRIPT_DEMO</TITLE>
<SCRIPT Language="JavaScript">
function sum()
{
var a,b,c;
a=10;
b=2;
c=a+b;
document.write("Sum is");
document.write(c);
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT Language="JavaScript">
sum( );
</SCRIPT>
</BODY>
</HTML>
Operators in JavaScript
• An operator is a symbol used to perform a
specific task. Almost all operators in JavaScript
are exactly similar to those in C++.
Arithmetic Operator
Arithmetic operator is used to perform arithmetic operations.
Relational operator
Relational operator is used for comparison operations
Arithmetic Assignment Operator
Assignment Operator
• The assignment operator(=) operator is used to assign
a value to a variable.
• Example:- var a=10; (Assigns 10 to the variable a.)
Arithmetic Assignment Operator
• The arithmetic assignment operators includes +=,-
=,* =,/ =,% =.They are used to simplify the use of
assignment operator.
• Example:-a+=10 is equal to a=a+10
• a% =10 is equal to a=a%10
Logical Operators
• Logical operators are used for comparison and
combine relational expressions.
• Given that x = 6 and y = 3, the table below
explains the logical operators:
Arithmetic Operator Precedence
• The following table lists JavaScript arithmetic
operators, ordered from highest to lowest
precedence:
String addition
The + operator can be used to add(Join) two strings.
Example:-
var a,b,c;
a=”Hello”;
b=”How are you”;
c=a+b;
document.write(c);
Output:- Hello How are you
Number function in JavaScript
• The Number( ) function is used to convert a
string data into a number.
• Example:-
• Number(“42”); //returns 42
• Number(“eggs”); //returns NaN
• String that can’t be converted to number
returns NaN.
• Number(false);//returns 0
Note:- NaN stands for Not a Number.
Eg: document.write(Number(true));//returns 1
Control structures in JavaScript
• Control structures are used to alter the normal
sequence of execution of a program.
• They are,If, switch, while,for etc. Syntax same
as in C++
1)if statement
• The if statement executes a group of statements
based on a condition.
• The syntax is
if(test_expression)
{
Statements;
}
if(test_expression)
{
Statements;
}
else
{
Statements
}
Control structures in JavaScript
2)Switch statement
• The Switch statement is a multi-branching
statement, which executes statement based on
value of the expression.
switch(expression)
{
case value1:
statement1;
break;
case value2:
statement2;
break;
----------------------
default: statement;
}
Control structures in JavaScript
3) while ......... loop
• The while loop executes a group of statements
repeatedly based on a condition.
• The syntax is
while(expression)
{
statements;
}
• For example
while(i <= n)
{
fact = fact * i;
i++;
}
Control structures in JavaScript
4) for......Loop
• The for loop executes a group of statements
repeatedly.
• The syntax is
for(initialisation;expression;update_statement)
{
Statements;
}
• For exmple
for(i=1; i<=n; i++)
{
fact = fact * i;
}
Built-in Functions
• Built-in functions are also called methods.
• The following are the important methods in
JavaScript.
1)alert( ) function
• The alert( ) function is used to display a
message on the screen.
• The syntax is
alert(“message”);
2)isNaN( ) function
• The isNaN( ) function is check if a value is a
number or not.
• The function returns True if the value is a
number. The syntax is : isNaN(test_value);
Built-in Functions
3)toUpperCase ( ) function
This function converts a string into uppercase.
a=”abcd”;
b=a.toUpperCase( );
document.write(b);
Output: ABCD
4)toLowerCase( ) function
• This function converts a string to lowercase.
a=”ABCD”;
b=a.toLowerCase( );
document.write(b);
Output: abcd
Built-in Functions
5)charAt( ) function
• This method returns the character at the
specified index in a string. The index of the first
character is 0, the second character is 1, and so
on.
Example:- var str = "HELLO WORLD";
var res = str.charAt(0);
returns H
6)length Property
• The length property returns the length of a
string(number of characters).
Example:-var a=”Welcome”;
var len=a.length;
document.write(len);
Accessing values in a textbox
• To Access values in a textbox using JavaScript,
Name must be provided to textbox.
• The following HTML code is used to specify name
to textbox.
<INPUT Type=”Text” Name=”txtnum”>;
• The above textbox can be accessed as
var n= document.txtnum.value;
• The above statement stores the value in txtnum in
variable n.
JavaScript Events
• JavaScript’s interaction with HTML is controlled
using events.
• JavaScripts reacts to events (click,keydown,keyup
etc).
• Events are actions that are initiated by the
user.The important events in JavaScript are,
Mouse Events
JavaScript Events
JavaScript Event Sample
Create a web page to create that display the square of a number
<HTML>
<HEAD>
<TITLE>JAVA SCRIPT</TITLE>
<SCRIPT Language="JavaScript">
function square()
{
var num,sqr;
num=document.frmSquare.txtNum.value;
sqr=num*num;
document.frmSquare.txtSqr.value=sqr;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM Name="frmSquare">
<CENTER>
Enter a Number :
<INPUT Type="text" name="txtNum">
<BR><BR>
Square :
<INPUT TYPE="text" name="txtSqr">
<BR><BR>
<INPUT Type="button"
value="Square" onClick="square()">
</CENTER>
</FORM>
</BODY></HTML>
Different methods to add script
Script can be placed inside the <BODY> or <HEAD> tag.
• Placing the script in <HEAD> tag helps to execute scripts
faster as the head section is loaded before the body section.
• The main disadvantage is that scripts that are to be executed
while loading the page will not work when they are placed in
the <HEAD> section.
Scripts can be placed into an external file ,saved with .’js’
extension.
• When scripts are placed in an external file it can be used by
multiple HTML pages and also helps to load pages faster.
• The file is linked to HTML file using the <SCRIPT> tag.
• For example,
<script Type=”text/JavaScript” Src=”process.js”>
The above code links the external file named process.js to the
HTML page
Display first 10 Even numbers
<HTML>
<BODY>
<SCRIPT Language="JavaScript">
var i;
for(i=2;i<=20;i=i+2)
{
document.write(i+"<BR>");
}
</SCRIPT>
</BODY>
</HTML>
Sum of first 10 Natural numbers
<HTML>
<head><title>Sum_of_Natural_Number</title>
</head>
<BODY>
<SCRIPT Language="JavaScript">
var i,s=0;
for(i=1;i<=10;i++)
{
s=s+i;
}
document.write("Sum ="+s);
</SCRIPT>
</BODY>
</HTML>
Sum of n Natural numbers using form
<SCRIPT Language="JavaScript">
function sum( )
{
var sum=0,i,limit;
limit=Number(document.frmsum.txtlimit.value);
for(i=1;i<=limit;i++)
{
sum=sum+i;
}
document.frmsum.txtsum.value=sum;
}</SCRIPT>
<BODY>
<FORM Name="frmsum">
<CENTER>
Enter the limit:
<INPUT Type="text" Name="txtlimit">
<BR><BR>
Sum:
<INPUT Type="text" name="txtsum">
<BR><BR>
<INPUT Type="button" value="Sum"
onClick="sum( )">
</CENTER> </FORM></BODY>
</HTML>
Check if a number is Even or Odd
<HTML>
<HEAD>
<TITLE>Even_Odd</TITLE>
<SCRIPT Language="JavaScript">
function check( )
{
var num1,rem;
num1=document.frmcheck.txtNum1.value;
rem=Number(num1)%2;
if(rem==0)
{
document.frmcheck.txtresult.value="Even";
}
else
{
document.frmcheck.txtresult.value="Odd";
}
} </SCRIPT>
</HEAD>
<FORM name=frmcheck>
<CENTER>
Enter a number :
<INPUT Type="text" name="txtNum1">
<BR><BR>
The number is :
<INPUT Type="text" name="txtresult">
<BR><BR>
<INPUT Type="Button" Value="show"
onClick="check ( )">
</CENTER>
</FORM>
</BODY>
Conclusion:-
Client sidescripting javascript

Más contenido relacionado

La actualidad más candente

INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++Vraj Patel
 
Functions in c
Functions in cFunctions in c
Functions in creshmy12
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVAMuskanSony
 
Functions in c++
Functions in c++Functions in c++
Functions in c++Maaz Hasan
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorialSURBHI SAROHA
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)Ritika Sharma
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaKnoldus Inc.
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageAzilen Technologies Pvt. Ltd.
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhHarmeet Singh(Taara)
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default argumentsNikhil Pandit
 
Overview of c language
Overview of c languageOverview of c language
Overview of c languageshalini392
 

La actualidad más candente (20)

INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Java 8 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Function C++
Function C++ Function C++
Function C++
 
Books
BooksBooks
Books
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVA
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Learn Java Part 2
Learn Java Part 2Learn Java Part 2
Learn Java Part 2
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In Scala
 
Functional go
Functional goFunctional go
Functional go
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
 

Similar a Client sidescripting javascript

Similar a Client sidescripting javascript (20)

Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)
 
Java script
Java scriptJava script
Java script
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptx
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
Java script.pptx v
Java script.pptx                                     vJava script.pptx                                     v
Java script.pptx v
 
Javascript
JavascriptJavascript
Javascript
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Javascript
JavascriptJavascript
Javascript
 
Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
 
Java script
Java scriptJava script
Java script
 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
 
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
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScript
 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3
 
BITM3730Week6.pptx
BITM3730Week6.pptxBITM3730Week6.pptx
BITM3730Week6.pptx
 

Más de Selvin Josy Bai Somu (7)

Web technology
Web technologyWeb technology
Web technology
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
Files in c++
Files in c++Files in c++
Files in c++
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
Inheritance
InheritanceInheritance
Inheritance
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 

Último

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 

Último (20)

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 

Client sidescripting javascript

  • 1.
  • 2. Java Script • It is a client side scripting Language used to validate data. • It is embedded in HTML document. • The <SCRIPT> tag is used to include scripts in an HTML page. • JavaScript was developed by Brendan Eich. • It is supported by almost all web browsers. • It follows exact the same syntax of C++. • It ignores spaces, tabs, and newlines that appear in JavaScript programs. • JavaScript is a case-sensitive language.
  • 3. Java Script <SCRIPT> Tag • The <SCRIPT> tag is used to include(embed) script in an HTML page. • The Language attribute of <SCRIPT> tag specifies the type of scripting language used. Example:- <SCRIPT Language=”JavaScript”> </SCRIPT>
  • 4. Output / input Functions Output Function • The document.write ( ) function • The function document.write which writes a string into our HTML document. <html> <body> <script language="javascript" > document.write("Welcome to JavaScript") ; </script> </body> </html>
  • 5. Output / input Functions Input Function • The prompt( message ) function • The function prompt which takes a string from keyboard to HTML document. <script language=“JavaScript"> n=prompt("Enter your Name"); document.write(n); </script>
  • 6. Creating functions in JavaScript • A function is a self-contained unit of a program that perform a specific task. • It is an independent part of a program which is executed when it is called. • Functions can be placed in the < HEAD> Tag of <HTML> Tag. • A function in JavaScript does not have return type • A function can be called using its name such as, print( ).
  • 7. Creating functions in JavaScript Defining a function • Functions must be declared before they are used. • A function is defined using the function keyword. • The function statements are enclosed in curly brace {} . • Once a function is defined it can be called many times. . A function can be called using its name such as, print( ).
  • 8. Data types in JavaScript • Data type specifies the type of data and the operations that can be performed on the data. • Data types in JavaScript is classified into two primitive data type and composite data type. Primitive data types The three primitive data types in JavaScript are Number, String and Boolean. Number:-They include integers and floating point numbers. Strings:-A string is a combination of characters, numbers or symbols enclosed within double quotes. Boolean:-A Boolean data can be either True or False.
  • 9. Variables in JavaScript • A variable is a data type whose value changes during program execution. • Variables in JavaScript are declared using the var keyword. Example:- var a; Declares a variable a. Example:- var msg=”Hello”; Note:-JavaScript determines the typeof variable only when assigning a value.
  • 10. Variables in JavaScript Example:-A web page to find the sum of two numbers <HTML><HEAD> <TITLE>JAVASCRIPT_DEMO</TITLE> <SCRIPT Language="JavaScript"> function sum() { var a,b,c; a=10; b=2; c=a+b; document.write("Sum is"); document.write(c); } </SCRIPT> </HEAD> <BODY> <SCRIPT Language="JavaScript"> sum( ); </SCRIPT> </BODY> </HTML>
  • 11. Operators in JavaScript • An operator is a symbol used to perform a specific task. Almost all operators in JavaScript are exactly similar to those in C++. Arithmetic Operator Arithmetic operator is used to perform arithmetic operations. Relational operator Relational operator is used for comparison operations
  • 12. Arithmetic Assignment Operator Assignment Operator • The assignment operator(=) operator is used to assign a value to a variable. • Example:- var a=10; (Assigns 10 to the variable a.) Arithmetic Assignment Operator • The arithmetic assignment operators includes +=,- =,* =,/ =,% =.They are used to simplify the use of assignment operator. • Example:-a+=10 is equal to a=a+10 • a% =10 is equal to a=a%10
  • 13. Logical Operators • Logical operators are used for comparison and combine relational expressions. • Given that x = 6 and y = 3, the table below explains the logical operators:
  • 14. Arithmetic Operator Precedence • The following table lists JavaScript arithmetic operators, ordered from highest to lowest precedence:
  • 15. String addition The + operator can be used to add(Join) two strings. Example:- var a,b,c; a=”Hello”; b=”How are you”; c=a+b; document.write(c); Output:- Hello How are you
  • 16. Number function in JavaScript • The Number( ) function is used to convert a string data into a number. • Example:- • Number(“42”); //returns 42 • Number(“eggs”); //returns NaN • String that can’t be converted to number returns NaN. • Number(false);//returns 0 Note:- NaN stands for Not a Number. Eg: document.write(Number(true));//returns 1
  • 17. Control structures in JavaScript • Control structures are used to alter the normal sequence of execution of a program. • They are,If, switch, while,for etc. Syntax same as in C++ 1)if statement • The if statement executes a group of statements based on a condition. • The syntax is if(test_expression) { Statements; } if(test_expression) { Statements; } else { Statements }
  • 18. Control structures in JavaScript 2)Switch statement • The Switch statement is a multi-branching statement, which executes statement based on value of the expression. switch(expression) { case value1: statement1; break; case value2: statement2; break; ---------------------- default: statement; }
  • 19. Control structures in JavaScript 3) while ......... loop • The while loop executes a group of statements repeatedly based on a condition. • The syntax is while(expression) { statements; } • For example while(i <= n) { fact = fact * i; i++; }
  • 20. Control structures in JavaScript 4) for......Loop • The for loop executes a group of statements repeatedly. • The syntax is for(initialisation;expression;update_statement) { Statements; } • For exmple for(i=1; i<=n; i++) { fact = fact * i; }
  • 21. Built-in Functions • Built-in functions are also called methods. • The following are the important methods in JavaScript. 1)alert( ) function • The alert( ) function is used to display a message on the screen. • The syntax is alert(“message”); 2)isNaN( ) function • The isNaN( ) function is check if a value is a number or not. • The function returns True if the value is a number. The syntax is : isNaN(test_value);
  • 22. Built-in Functions 3)toUpperCase ( ) function This function converts a string into uppercase. a=”abcd”; b=a.toUpperCase( ); document.write(b); Output: ABCD 4)toLowerCase( ) function • This function converts a string to lowercase. a=”ABCD”; b=a.toLowerCase( ); document.write(b); Output: abcd
  • 23. Built-in Functions 5)charAt( ) function • This method returns the character at the specified index in a string. The index of the first character is 0, the second character is 1, and so on. Example:- var str = "HELLO WORLD"; var res = str.charAt(0); returns H 6)length Property • The length property returns the length of a string(number of characters). Example:-var a=”Welcome”; var len=a.length; document.write(len);
  • 24. Accessing values in a textbox • To Access values in a textbox using JavaScript, Name must be provided to textbox. • The following HTML code is used to specify name to textbox. <INPUT Type=”Text” Name=”txtnum”>; • The above textbox can be accessed as var n= document.txtnum.value; • The above statement stores the value in txtnum in variable n.
  • 25. JavaScript Events • JavaScript’s interaction with HTML is controlled using events. • JavaScripts reacts to events (click,keydown,keyup etc). • Events are actions that are initiated by the user.The important events in JavaScript are, Mouse Events
  • 27. JavaScript Event Sample Create a web page to create that display the square of a number <HTML> <HEAD> <TITLE>JAVA SCRIPT</TITLE> <SCRIPT Language="JavaScript"> function square() { var num,sqr; num=document.frmSquare.txtNum.value; sqr=num*num; document.frmSquare.txtSqr.value=sqr; } </SCRIPT> </HEAD> <BODY> <FORM Name="frmSquare"> <CENTER> Enter a Number : <INPUT Type="text" name="txtNum"> <BR><BR> Square : <INPUT TYPE="text" name="txtSqr"> <BR><BR> <INPUT Type="button" value="Square" onClick="square()"> </CENTER> </FORM> </BODY></HTML>
  • 28. Different methods to add script Script can be placed inside the <BODY> or <HEAD> tag. • Placing the script in <HEAD> tag helps to execute scripts faster as the head section is loaded before the body section. • The main disadvantage is that scripts that are to be executed while loading the page will not work when they are placed in the <HEAD> section. Scripts can be placed into an external file ,saved with .’js’ extension. • When scripts are placed in an external file it can be used by multiple HTML pages and also helps to load pages faster. • The file is linked to HTML file using the <SCRIPT> tag. • For example, <script Type=”text/JavaScript” Src=”process.js”> The above code links the external file named process.js to the HTML page
  • 29. Display first 10 Even numbers <HTML> <BODY> <SCRIPT Language="JavaScript"> var i; for(i=2;i<=20;i=i+2) { document.write(i+"<BR>"); } </SCRIPT> </BODY> </HTML>
  • 30. Sum of first 10 Natural numbers <HTML> <head><title>Sum_of_Natural_Number</title> </head> <BODY> <SCRIPT Language="JavaScript"> var i,s=0; for(i=1;i<=10;i++) { s=s+i; } document.write("Sum ="+s); </SCRIPT> </BODY> </HTML>
  • 31. Sum of n Natural numbers using form <SCRIPT Language="JavaScript"> function sum( ) { var sum=0,i,limit; limit=Number(document.frmsum.txtlimit.value); for(i=1;i<=limit;i++) { sum=sum+i; } document.frmsum.txtsum.value=sum; }</SCRIPT> <BODY> <FORM Name="frmsum"> <CENTER> Enter the limit: <INPUT Type="text" Name="txtlimit"> <BR><BR> Sum: <INPUT Type="text" name="txtsum"> <BR><BR> <INPUT Type="button" value="Sum" onClick="sum( )"> </CENTER> </FORM></BODY> </HTML>
  • 32. Check if a number is Even or Odd <HTML> <HEAD> <TITLE>Even_Odd</TITLE> <SCRIPT Language="JavaScript"> function check( ) { var num1,rem; num1=document.frmcheck.txtNum1.value; rem=Number(num1)%2; if(rem==0) { document.frmcheck.txtresult.value="Even"; } else { document.frmcheck.txtresult.value="Odd"; } } </SCRIPT> </HEAD> <FORM name=frmcheck> <CENTER> Enter a number : <INPUT Type="text" name="txtNum1"> <BR><BR> The number is : <INPUT Type="text" name="txtresult"> <BR><BR> <INPUT Type="Button" Value="show" onClick="check ( )"> </CENTER> </FORM> </BODY>