to add functionality, validate forms, detect
browsers, and much more.
11/30/2011 1Hassan Khan
A scripting language is a lightweight programming
scripts execute without preliminary compilation)
11/30/2011 2Hassan Khan
11/30/2011 3Hassan Khan
How to Handle Simple
The HTML comment tag should be used to "hide" the
Just add an HTML comment tag <!-- before the first
11/30/2011 4Hassan Khan
The two forward slashes at the end of comment line (//) is
11/30/2011 5Hassan Khan
11/30/2011 6Hassan Khan
How To Use?
an HTML page.
Between <body> tag
Between <head> tag
11/30/2011 7Hassan Khan
How To Use (Cont.)?
executed WHILE the page loads.
executed when CALLED.
11/30/2011 8Hassan Khan
Use of semicolon(;) in the end of statement is
11/30/2011 9Hassan Khan
Single line comments start with //.
Multi line comments start with /* and end with
11/30/2011 10Hassan Khan
x=5, y=6, z=x+y
Variable names are case sensitive (y and Y
are two different variables)
Variable names must begin with a letter or
the underscore character
11/30/2011 11Hassan Khan
11/30/2011 12Hassan Khan
+ Operator and Strings
To add two or more string variables together,
use the + operator.
11/30/2011 15Hassan Khan
11/30/2011 16Hassan Khan
11/30/2011 17Hassan Khan
used to perform different actions based on different
if statement - use this statement to execute some
code only if a specified condition is true
if...else statement - use this statement to execute
some code if the condition is true and another code
if the condition is false
if...else if....else statement - use this statement to
select one of many blocks of code to be executed
switch statement - use this statement to select one
of many blocks of code to be executed
11/30/2011 18Hassan Khan
11/30/2011 19Hassan Khan
11/30/2011 20Hassan Khan
11/30/2011 21Hassan Khan
used to perform different actions based on
11/30/2011 22Hassan Khan
11/30/2011 23Hassan Khan
alert(“Hello Every Body");
confirm(“Press a button");
A function will be executed by an event or by
a call to the function.
11/30/2011 25Hassan Khan
11/30/2011 26Hassan Khan
You want the same block of code to run over and
over again in a row. Instead of adding several
almost equal lines in a script we can use loops to
perform a task like this.
for - loops through a block of code a specified
number of times
while - loops through a block of code while a
specified condition is true
11/30/2011 27Hassan Khan
The for Loop
11/30/2011 28Hassan Khan
11/30/2011 29Hassan Khan
The break Statement
The break statement will break the loop and
continue executing the code that follows after
the loop (if any).
11/30/2011 30Hassan Khan
The continue Statement
The continue statement will break the current
loop and continue with the next value.
11/30/2011 31Hassan Khan
Events are actions that can be detected by
Examples of events:
A mouse click
A web page or an image loading
Mousing over a hot spot on the web page
Selecting an input field in an HTML form
Submitting an HTML form
11/30/2011 32Hassan Khan
onLoad and onUnload
onFocus, onBlur and onChange
onMouseOver and onMouseOut
11/30/2011 33Hassan Khan
Programming (OOP) language.
An OOP language allows you to define your
own objects and make your own variable
We will start by looking at the built-in
11/30/2011 34Hassan Khan
Properties are the values associated with an
11/30/2011 35Hassan Khan
The String object is used to manipulate a
stored piece of text.
Some String Methods
11/30/2011 36Hassan Khan
The Date object is used to work with dates
11/30/2011 37Hassan Khan
11/30/2011 38Hassan Khan
The Array object is used to store multiple
values in a single variable.
An array can be defined in three ways.
11/30/2011 39Hassan Khan
The Math object allows you to perform
11/30/2011 40Hassan Khan
The Navigator object allows you to
check/validate your Browser.
11/30/2011 41Hassan Khan