JAVA SCRIPT
Dr.K.R.PRASANNA KUMAR/IT
1
Introduction to Scripting
4
History
3
Introduction
4
Introduction
5
Introduction
6
Introduction
7
Introduction
8
Introduction
9
Introduction
10
Display Options
11
12
window. document.getElementById("header");
Or
document.getElementById("header");
13
Introduction
14
Introduction
15
Introduction
Display using alert box:
16
JavaScript Display Possibilities
17
JS Methods-Sample
18
JS Methods-Sample
19
JS-Modes
20
JS-Modes
21
JS-Modes
22
JS-Modes
23
Variables and Data Types
15
JavaScript Values
25
Variables
26
Variables
27
Variables
1.Names can contain letters, digits, underscores, and dollar signs.
2.Names must begin with a letter,$ and _
3.Names are case sensitive
4.Keywords cannot be used as variables
28
Variables
29
Operators
20
Operators
31
Operators
Arithmetic operators are used to perform arithmetic on numbers
32
Operators-Arithmetic operators
33
Operators
34
Operators
35
Operators
36
Operators
variablename = (condition) ? value1:value2
voteable = (age < 18) ? "Too young":"Old enough";
37
Control Statements
22
Control statements
39
Control statements
40
Control statements
41
If-else Selection statements
if (condition){� // block of code to be executed if the condition is true�}
if (condition) {� // block of code to be executed if the condition is true�} else { � // block of code to be executed if the condition is false�}
42
If-else Selection statements
if (condition1) {� // if condition1 is true�}
else if (condition2) {� // if the condition1 is false and condition2 is true�}
else {� // if the condition1 is false and condition2 is false�}
43
If-else Selection statements
44
Switch statement
switch(expression) {� case x:� // code block� break;� case y:� // code block� break;� default:� // code block�}
45
Switch statement
46
JS-Looping structure
Loops can execute a block of code a number of times
47
For Loop
for (statement 1; statement 2; statement 3) {� // code block to be executed�}
48
For-in Loop
49
For-of Loop
Syntax: for (variable of iterable) {� // code block to be executed� }
50
While Loop
51
Do-while Loop
52
Break and continue
53
Break and continue
Continue
54
Functions
13
JS Functions
56
JS Functions
function name(parameter1, parameter2, parameter3)
{� // code to be executed� }
A recursive function is a function that calls itself, either directly, or indirectly through another function
57
JS Functions
58
JS Recursive Functions
59
Built-in Functions
28
Built-in Functions
61
Built-in Functions
62
Built-in Functions
63
Built-in Functions
64
Scope
28
JS-Scope
Local scope
Global scope
Variables declared within a JavaScript function, become LOCAL to the function
66
JS-Scope
67
JS-Scope
A variable declared outside a function, becomes GLOBAL
68
JS-Arrays
69
Declaring and Allocating Arrays
var c = new Array( 12 );
[OR]
var c; // declares a variable that will hold the array
c = new Array( 12 ); // allocates the array
70
Different Ways of Initializing a List
71
72
73
Array Declaration
74
Passing Arrays to functions
75
Displaying Output in Table
<html>
<head>
</head>
<body>
<div id ="outone"> </div>
<div id ="outtwo"> </div>
76
77
Book Example
78
79
Declaration of array
Initialization of array
Passing Array as argument
Output placed in table
OUTPUT
80
Passing Array to Function
81
Output
82
Passing Arrays & converting them to string
83
Passing Arrays & converting them to string
84
Passing Arrays & converting them to string[Book Example]
85
Passing Array to Function �[Book Example cont’d…]
86
JS-Event Handling
87
Event Handling
88
Registering an Event - addEvent Listener
Syntax:
addEventListener(“Event”, Function, usecapture);
Example:
window.addEventListener( "load", startTimer, false );
89
Example
90
Events
91
OnLoad Event
92
Mouse Events
93
mousemove event example
94
mousemove and mouseout
95
Event.target
96
Event.target
97
mouseover and mouseout
98
Mousemove-Book Example
99
100
mouseover,mouseout-Book Eample
101
Javascript Code
102
Form Events
103
Example
104
Event bubbling
105
Example
106
107
108
Thank you
109