NETWORK COMPUTING – MODULE 2
MODULE 2
CLIENT-SIDE SCRIPTING
"Client-Side" refers to activities that happen on the client machine. -- for example, form
validation is normally done at client. In the case of registration form some fields are set as
mandatory. Before submitting the form to the server the client can verify the validity of that
fields. In some other cases we can set the type of data that can be entered in to a field, for
example age field contains only numbers. Here also the client can verify the validity.
"Scripting" is a kind of programming, or coding. (These terms have some differences, but
are generally interchangeable.)
Client-side scripts run on the client.
INTRODUCTION TO JAVA SCRIPT
JavaScript is the most popular scripting language on the internet, and works in all major
browsers, such as Internet Explorer, Mozilla, Firefox, Netscape, and Opera.
JavaScript was designed to add interactivity to HTML pages
JavaScript is a scripting language
A scripting language is a lightweight programming language
A JavaScript consists of lines of executable computer code
A JavaScript is usually embedded directly into HTML pages
JavaScript is an interpreted language (means that scripts execute without preliminary
compilation)
Everyone can use JavaScript without purchasing a license
JavaScript gives HTML designers a programming tool - HTML authors are normally not
programmers, but JavaScript is a scripting language with a very simple syntax! Almost
anyone can put small "snippets" of code into their HTML pages
, NETWORK COMPUTING – MODULE 2
JavaScript can put dynamic text into an HTML page - A JavaScript statement like this:
document. write("<h1>" + name + "</h1>") can write a variable text into an HTML page
JavaScript can react to events - A JavaScript can be set to execute when something
happens, like when a page has finished loading or when a user clicks on an HTML
element
JavaScript can read and write HTML elements - A JavaScript can read and change the
content of an HTML element
JavaScript can be used to validate data - A JavaScript can be used to validate form data
before it is submitted to a server. This saves the server from extra processing
JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect
the visitor's browser, and - depending on the browser - load another page specifically
designed for that browser
JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve
information on the visitor's computer
Variables
A variable is a "container" for information you want to store. A variable's value can change
during the script. You can refer to a variable by name to see its value or to change its value.
Rules for variable names:
Variable names are case sensitive
They must begin with a letter or the underscore character
JavaScript is case-sensitive!
Declare a Variable
You can create a variable with the var statement:
var strname = some value
, NETWORK COMPUTING – MODULE 2
You can also create a variable without the var statement: strname = some value
Assign a Value to a Variable
You can assign a value to a variable like this:
var strname = "Hege"
Or like this:
strname = "Hege"
The variable name is on the left side of the expression and the value you want to assign to the
variable is on the right. Now the variable "strname" has the value "Hege".
Lifetime of Variables
When you declare a variable within a function, the variable can only be accessed within that
function. When you exit the function, the variable is destroyed. These variables are called local
variables. You can have local variables with the same name in different functions, because each
is recognized only by the function in which it is declared.
If you declare a variable outside a function, all the functions on your page can access it. The
lifetime of these variables starts when they are declared, and ends when the page is closed.
Operators
Arithmetic Operators
Operator Description Example Result
x=2,y=2
+ Addition 4
x+y
x=5,y=2
- Subtraction 3
x-y
x=5,y=4
* Multiplication 20
x*y
15/5 3
/ Division
5/2 2.5
5%2 1
% Modulus (division remainder) 10%8 2
10%2 0
MODULE 2
CLIENT-SIDE SCRIPTING
"Client-Side" refers to activities that happen on the client machine. -- for example, form
validation is normally done at client. In the case of registration form some fields are set as
mandatory. Before submitting the form to the server the client can verify the validity of that
fields. In some other cases we can set the type of data that can be entered in to a field, for
example age field contains only numbers. Here also the client can verify the validity.
"Scripting" is a kind of programming, or coding. (These terms have some differences, but
are generally interchangeable.)
Client-side scripts run on the client.
INTRODUCTION TO JAVA SCRIPT
JavaScript is the most popular scripting language on the internet, and works in all major
browsers, such as Internet Explorer, Mozilla, Firefox, Netscape, and Opera.
JavaScript was designed to add interactivity to HTML pages
JavaScript is a scripting language
A scripting language is a lightweight programming language
A JavaScript consists of lines of executable computer code
A JavaScript is usually embedded directly into HTML pages
JavaScript is an interpreted language (means that scripts execute without preliminary
compilation)
Everyone can use JavaScript without purchasing a license
JavaScript gives HTML designers a programming tool - HTML authors are normally not
programmers, but JavaScript is a scripting language with a very simple syntax! Almost
anyone can put small "snippets" of code into their HTML pages
, NETWORK COMPUTING – MODULE 2
JavaScript can put dynamic text into an HTML page - A JavaScript statement like this:
document. write("<h1>" + name + "</h1>") can write a variable text into an HTML page
JavaScript can react to events - A JavaScript can be set to execute when something
happens, like when a page has finished loading or when a user clicks on an HTML
element
JavaScript can read and write HTML elements - A JavaScript can read and change the
content of an HTML element
JavaScript can be used to validate data - A JavaScript can be used to validate form data
before it is submitted to a server. This saves the server from extra processing
JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect
the visitor's browser, and - depending on the browser - load another page specifically
designed for that browser
JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve
information on the visitor's computer
Variables
A variable is a "container" for information you want to store. A variable's value can change
during the script. You can refer to a variable by name to see its value or to change its value.
Rules for variable names:
Variable names are case sensitive
They must begin with a letter or the underscore character
JavaScript is case-sensitive!
Declare a Variable
You can create a variable with the var statement:
var strname = some value
, NETWORK COMPUTING – MODULE 2
You can also create a variable without the var statement: strname = some value
Assign a Value to a Variable
You can assign a value to a variable like this:
var strname = "Hege"
Or like this:
strname = "Hege"
The variable name is on the left side of the expression and the value you want to assign to the
variable is on the right. Now the variable "strname" has the value "Hege".
Lifetime of Variables
When you declare a variable within a function, the variable can only be accessed within that
function. When you exit the function, the variable is destroyed. These variables are called local
variables. You can have local variables with the same name in different functions, because each
is recognized only by the function in which it is declared.
If you declare a variable outside a function, all the functions on your page can access it. The
lifetime of these variables starts when they are declared, and ends when the page is closed.
Operators
Arithmetic Operators
Operator Description Example Result
x=2,y=2
+ Addition 4
x+y
x=5,y=2
- Subtraction 3
x-y
x=5,y=4
* Multiplication 20
x*y
15/5 3
/ Division
5/2 2.5
5%2 1
% Modulus (division remainder) 10%8 2
10%2 0