Part 1 Java Script
Part 1 Java Script
JAVASCRIPT
1. INTRODUCTION
a. Scripting language
b. Client-side language
c. Object-based language i.e., do not have polymorphism or inheritance or both
d. Interpreted language. Browser has the interpreter.
e. Light weighted and do not require server interaction. So, the response is faster.
f. No API for networking, don't have concept of file handling, multithreading, and multi-processing.
g. User inputs can be validated before sending the data to the server.
2. INCORPORATING JAVASCRIPT
<script type="text/javascript">
document.write("CSE3A")
</script>
ii. Two ways:
a. Internally: embedding js code in html. There is only one file i.e. file with .html extension
i. in body tag
ii. in head tag
b. Externally: in separate .js file. There will be two separate files. one with .js extension and
other .html
3. JAVASCRIPT COMMENTS
a. Single line comments: //
b. Multiple line comments: /* */
4. VARIABLE
var a = 10 or a = 1.02
4.1. CONVENTIONS
a. Local Scope:
i. Function scope: Variables declared Locally (inside a function) have Function
Scope.
ii. Block scope: Variables declared with the var keyword cannot have Block Scope.
Variables declared inside a block {} can be accessed from outside the
block. Before ES2015 JavaScript did not have Block Scope.
Variables declared with the let keyword can have Block Scope.
Variables declared inside a block {} cannot be accessed from outside
the block.
b. Global Scope: Variables declared Globally (outside any function) have Global Scope.
Global variables can be accessed from anywhere in a JavaScript program.
5. DATA TYPES
JavaScript provides different data types to hold different types of values. There are two types of data
types in JavaScript.
1. Primitive data type
2. Non-primitive (reference) data type
JavaScript is a dynamically-typed language; means we don't need to specify type of the variable
because it is dynamically used by JavaScript engine. It can hold any type of values such as numbers,
strings etc. For example:
1. var a=5; //holding number
2. var b="CSE3A"; //holding string
There are five types of primitive data types in JavaScript. They are as follows:
Null represents null i.e., no value at all. The property is defined, but the object
it refers to does not exist. The DOM methods getElementById(),
nextSibling(), childNodes[n], parentNode()
//and so, on return null (defined but having no value) when the call does
not return a node object.
Numbers:
A number data type can be an integer, a floating-point value, an exponential value, a ‘NaN’ or a
‘Infinity’.
A ‘NaN’ results when we try to perform an operation on a number with a non-numeric value
var c = Number(5);
console.log(c); // This will return 5
We can create a number object using the ‘new’ operator and the Number() constructor:
String:
The string data type in JavaScript can be any group of characters enclosed by a single or double-quotes
or by backticks.
var str1 = “This is a string1”; // This is a string primitive type or string literal
var str2= ‘This is a string2’;
var str3 = `This is a string3`;
var str4 = String(‘hi’); // This creates a string literal with value ' ‘hi’
Like the ‘number’ and the ‘boolean’ data types, a ‘String’ object can be created using the ‘new’
operator:
Boolean:
The boolean data type has only two values, true and false. It is mostly used to check a logical condition.
Thus, Booleans are logical data types which can be used for comparison of two variables or to check a
condition. The true and false implies a ‘yes’ for ‘true’ and a ‘no’ for ‘false in some places when we
check a condition or the existence of a variable or a value.
When we check the data type of ‘true’ or ‘false’ using typeof operator, it returns a boolean.
var a =5;
var b=6;
a==b // returns false
if(a<b){
alert(a is a smaller number than b);
}
If the above condition ‘a < b’ is true, the alert will pop on the screen.
var check = Boolean(expression); // If the expression evaluates to true, the value of ‘check’ will be
true or else it will be false.
var check = Boolean(a<b); // the expression evaluates to true, thus the value of check will be true.
Though we can create an object of the primitive data types, ‘number’,’boolean’ and ‘number’ it is
advisable or good practice to use the primitive version of these types.
Undefined:
Undefined data type means a variable that is not defined. The variable is declared but doesn’t contain
any value. So, you can say that undefined means lack of value or unknown value.
var a;
console.log(a); // This will return undefined.
The variable ‘a’ has been declared but hasn’t been assigned a value yet.
We can assign a value to a:
a=5;
console.log(a); // This will return 5
Null:
The null in JavaScript is a data type that is represented by only one value, the ‘null’ itself. A null value
means no value.
You can assign null to a variable to denote that currently that variable does not have any value but it
will have later on. A null means absence of a value.
A null value evaluates to false in conditional expression. So you don't have to use comparison operators
like === or !== to check for null values.
6. OPERATORS
JavaScript operators are symbols that are used to perform operations on operands. For example:
var sum=10+20;
a) Arithmetic Operators
b) Comparison (Relational) Operators
c) Bitwise Operators
d) Logical Operators
e) Assignment Operators
f) Special Operators
Arithmetic operators are used to perform arithmetic operations on the operands. The following operators
are known as JavaScript arithmetic operators.
+ Addition 10+20 = 30
- Subtraction 20-10 = 10
/ Division 20/10 = 2
The JavaScript comparison operator compares the two operands. The comparison operators are as
follows:
The bitwise operators perform bitwise operations on operands. The bitwise operators are as follows:
= Assign 10+10 = 20
Operator Description
(?:) Conditional Operator returns value based on the condition. It is like if-else.
7. CONDITIONAL STATEMENTS
7.1 IF-ELSE
The if-else statement is used to execute the code whether condition is true or false. There are three
forms of if statement in JavaScript.
1. If Statement
2. If else statement
3. if else if statement
7.1.1. IF STATEMENT
It evaluates the content only if expression is true. The signature of JavaScript if statement is given
below.
if(expression){
//content to be evaluated
}
<script>
var a=20;
if(a>10){
document.write("value of a is greater than 10");
}
</script>
Output of the above example
value of a is greater than 10
It evaluates the content whether condition is true of false. The syntax of JavaScript if-else statement is
given below.
if(expression){
//content to be evaluated if condition is true
}
else{
//content to be evaluated if condition is false
}
Let’s see the example of if-else statement in JavaScript to find out the even or odd number.
<script>
var a=20;
if(a%2==0){
document.write("a is even number");
}
else{
document.write("a is odd number");
}
</script>
Output of the above example
a is even number
It evaluates the content only if expression is true from several expressions. The signature of JavaScript
if else if statement is given below.
if(expression1){
//content to be evaluated if expression1 is true
} else if(expression2){
//content to be evaluated if expression2 is true
} else if(expression3){
//content to be evaluated if expression3 is true
} else{
//content to be evaluated if no expression is true
}
var a=20;
if(a==10){
document.write("a is equal to 10");
} else if(a==15){
document.write("a is equal to 15");
}else if(a==20){
document.write("a is equal to 20");
} else{
document.write("a is not equal to 10, 15 or 20");
}
7.1.4. SWITCH
The JavaScript switch statement is used to execute one code from multiple expressions. It is just like
else if statement that we have learned in previous page. But it is convenient than if..else..if because it
can be used with numbers, characters etc.
switch(expression){
case value1:
code to be executed;
break;
case value2:
code to be executed;
break;
......
default:
code to be executed if above values are not matched;
}
<script>
var grade='B';
var result;
switch(grade){
case 'A':
result="A Grade";
break;
case 'B':
result="B Grade";
break;
case 'C':
result="C Grade";
break;
default:
result="No Grade";
}
document.write(result);
</script>
<script>
var grade='B';
var result;
switch(grade){
case 'A':
result+=" A Grade";
case 'B':
result+=" B Grade";
case 'C':
result+=" C Grade";
default:
result+=" No Grade";
}
document.write(result);
</script>
8. LOOPS
The loops are used to iterate the piece of code using for, while, do while or for-in loops. It makes
the code compact. It is mostly used in array.
1. for loop
2. while loop
3. do-while loop
4. for-in loop
<script>
for (i=1; i<=5; i++)
{
document.write(i + "<br/>")
}
</script>
Output:
1
2
3
4
5
while (condition)
{
code to be executed
}
Let’s see the simple example of while loop in javascript.
<script>
var i=11;
while (i<=15)
{
document.write(i + "<br/>");
i++;
}
</script>
Output:
11
12
13
14
15
do{
code to be executed
}while (condition);
<script>
var i=21;
do{
document.write(i + "<br/>");
i++;
}while (i<=25);
</script>
Output:
21
22
23
24
25
10. FUNCTIONS
Functions are used to perform operations. Declared functions are not executed immediately. They
are "saved for later use", and will be executed later, when they are invoked (called upon). We can
call JavaScript function many times to reuse the code.
Let’s see the simple example of function in JavaScript that does not has arguments.
<script>
function msg(){
alert("hello! this is message");
}
</script>
<input type="button" onclick="msg()" value="call function"/>
We can call function by passing arguments. Let’s see the example of function that has one argument.
<script>
function getcube(number){
alert(number*number*number);
}
</script>
<form>
<input type="button" value="click" onclick="getcube(4)"/>
</form>
A JavaScript function can also be defined using an expression. A function expression can be stored
in a variable. After a function expression has been stored in a variable, the variable can be used as a
function.
<script>
var x = function (a, b) {return a * b};
document.write(x(4, 3));
</script>
The function above is actually an anonymous function (a function without a name). Functions
stored in variables do not need function names. They are always invoked (called) using the variable
name.
As you have seen in the previous examples, JavaScript functions are defined with
the function keyword.
Functions can also be defined with a built-in JavaScript function constructor called Function().
<script>
var myFunction = new Function("a", "b", "return a * b");
var x = myFunction(4, 3);
document.write(x)
</script>
Above code is same as:
<script>
var myFunction = function (a, b) {return a * b};
var x = myFunction(4, 3);
document.write(x)
</script>
Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top
of their scope before code execution. Inevitably, this means that no matter where functions and
variables are declared, they are moved to the top of their scope regardless of whether their scope is
global or local.
<script>
myFunction(5);
function myFunction(y) {
return y * y;
}
</script>
<script>
(function () {
var x = "Hello!!";
document.write(x + "I will invoke myself")
}) ();
</script>
The function above is actually an anonymous self-invoking function (function without name).
The code inside the function will execute when "something" invokes (calls) the function:
We can call function that returns a value and use it in our program. Let’s see the example of function
that returns value.
<script>
function getInfo(){
return "hello ! How r u?";
}
</script>
<script>
document.write(getInfo());
</script>
Output of the above example
hello! How r u?
JavaScript provides different built-in functions to display popup messages for different purposes
e.g. to display a simple message or display a message and take user's confirmation on it or display a
popup to take a user's input value.
Use alert() function to display a popup message to the user. This popup will have OK button to close
the popup.
The alert function can display message of any data type e.g. string, number, boolean etc. There is no
need to convert a message to string type.
Sometimes you need to take the user's confirmation to proceed. For example, you want to take user's
confirmation before saving updated data or deleting existing data. In this scenario, use JavaScript
built-in function confirm(). The confirm() function displays a popup message to the user with two
buttons, OK and Cancel. You can check which button the user has clicked and proceed accordingly.
Sometimes you may need to take the user's input to do further actions in a web page. For example,
you want to calculate EMI based on users' preferred tenure of loan. For this kind of scenario, use
JavaScript built-in function prompt().
Prompt function takes two string parameters. First parameter is the message to be displayed and
second parameter is the default value which will be in input text when the message is displayed.
Syntax:
Example:
if (tenure != null) {
As you can see in the above example, we have specified a message as first parameter and default
value "15" as second parameter. The prompt function returns a user entered value. If user has not
entered anything then it returns null. So, it is recommended to check null before proceeding.
Note:
The alert, confirm and prompt functions are global functions. So it can be called using window object
like window.alert(), window.confirm() and window.prompt().
Points to Remember:
1. Popup message can be shown using global functions - alert(), confirm() and prompt().
2. alert() function displays popup message with 'Ok' button.
3. confirm() function display popup message with 'Ok' and 'Cancel' buttons. Use confirm()
function to take user's confirmation to proceed.
4. prompt() function enables you to take user's input with 'Ok' and 'Cancel' buttons. prompt()
function returns value entered by the user. It returns null if the user does not provide any input
value.
A JavaScript object is an entity having state and behavior (properties and method). For example: car,
pen, bike, chair, glass, keyboard, monitor etc.
i. BY OBJECT LITERAL
object={property1:value1,property2:value2.....propertyN:valueN}
<script>
emp={id:102,name:"Shyam Kumar",salary:40000}
document.write(emp.id+" "+emp.name+" "+emp.salary);
</script>
<script>
var emp=new Object();
emp.id=101;
emp.name="Ravi Malik";
emp.salary=50000;
document.write(emp.id+" "+emp.name+" "+emp.salary);
</script>
Here, you need to create function with arguments. Each argument value can be assigned in the current
object by using this keyword.
<script>
function emp(id,name,salary){
this.id=id;
this.name=name;
this.salary=salary;
}
e=new emp(103,"Rakesh",30000);
document.write(e.id+" "+e.name+" "+e.salary);
</script>
We can define method in JavaScript object. But before defining method, we need to add property in
the function with same name as method.
<script>
function emp(id,name,salary){
this.id=id;
this.name=name;
this.salary=salary;
this.changeSalary=changeSalary;
function changeSalary(otherSalary){ // can be defined outside/inside the constructor
this.salary=otherSalary;
}
}
e=new emp(103,"ABC",30000);
document.write(e.id+" "+e.name+" "+e.salary);
e.changeSalary(45000);
document.write("<br>"+e.id+" "+e.name+" "+e.salary);
</script>
Output of the above example
103 ABC 30000
103 ABC 45000
1) BY ARRAY LITERAL
Let's see the simple example of creating and using array in JavaScript.
<script>
var ele=["A","B","C"];
for (i=0;i<ele.length;i++){
document.write(ele[i] + "<br/>");
}
</script>
A
B
C
<script>
var i;
var ele = new Array();
ele[0] = "Arun";
ele[1] = "Varun";
ele[2] = "John";
for (i=0;i<emp.length;i++){
document.write(emp[i] + "<br>");
}
</script>
Arun
Varun
John
Here, you need to create instance of array by passing arguments in constructor so that we don't have to
provide value explicitly.
<script>
var emp=new Array("Jai", "Vijay", "Smith");
for (i=0;i<emp.length;i++){
document.write(emp[i] + "<br>");
}
</script>
Jai
Vijay
Smith
a. concat() Method
The JavaScript array concat() method combines two or more arrays and returns a new string. This
method doesn't make any change in the original array. Also, it doesn’t remove the duplicate elements
array.concat(arr1,arr2,....,arrn)
<script>
var arr1=["C","C++","Python"];
var arr2=["Java","JavaScript","Android"];
var result=arr1.concat(arr2);
document.writeln(result);
</script>
Output:
C,C++,Python,Java,JavaScript,Android
b. pop() method
The JavaScript array pop() method removes the last element from the given array and return that
element. This method changes the length of the original array.
Syntax
1. array.pop()
Return
Example 1
<script>
var arr=["AngularJS","Node.js","JQuery"];
document.writeln("Orginal array: "+arr+"<br>");
document.writeln("Extracted element: "+arr.pop()+"<br>");
document.writeln("Remaining elements: "+ arr);
</script>
Output:
In this example, we will pop all the elements from the given array.
<script>
var arr=["AngulaJS","Node.js","JQuery"];
var len=arr.length;
for(var x=1;x<=len;x++)
{
document.writeln("Extracted element: "+arr.pop()+"<br>");
}
</script>
Output:
c. push() method
The JavaScript array push() method adds one or more elements to the end of the given array. This
method changes the length of the original array.
Syntax
array.push(element1,element2....elementn)
Parameter
Return
Example 1
<script>
var arr=["AngularJS","Node.js"];
arr.push("JQuery");
document.writeln(arr);
</script>
Output:
AngularJS,Node.js,JQuery
Example 2
Let's see an example to add more than one element in the given array.
<script>
var arr=["AngularJS","Node.js"];
document.writeln("Length before invoking push(): "+arr.length+"<br>");
arr.push("JQuery","Bootstrap");
document.writeln("Length after invoking push(): "+arr.length+"<br>");
document.writeln("Update array: "+arr);
</script>
Output:
The JavaScript array reverse() method changes the sequence of elements of the given array and returns
the reverse sequence. In other words, the arrays last element becomes first and the first element becomes
the last. This method also made the changes in the original array.
Syntax
array.reverse()
Return
Example
<script>
var arr=["AngulaJS","Node.js","JQuery"];
var rev=arr.reverse();
document.writeln(rev);
</script>
Output:
JQuery,Node.js,AngulaJS
e. shift() method
The JavaScript array shift() method removes the first element of the given array and returns that
element. This method changes the length of the original array.
Syntax
array. shift()
Return
Example
<script>
var arr=["AngularJS","Node.js","JQuery"];
var result=arr.shift();
document.writeln(result);
</script>
Output:
AngularJS
The JavaScript array slice() method extracts the part of the given array and returns it. This method
doesn't change the original array. The slice() method creates a new array. It does not remove any
elements from the source array. Similar to slicing in Python
Syntax
array.slice(start,end)
Parameter
start - It is optional. It represents the index from where the method starts to extract the elements.
end - It is optional. It represents the index at where the method stops extracting elements.
Return
Example 1
Let's see a simple example to extract an element from the given array.
<script>
var arr=["AngularJS","Node.js","JQuery","Bootstrap"]
var result=arr.slice(1,2);
document.writeln(result);
</script>
Output:
Node.js
Example 2
Let's see one more example to extract various element from the given array.
<script>
var arr=["AngularJS","Node.js","JQuery","Bootstrap"]
var result=arr.slice(0,3);
document.writeln(result);
</script>
Output:
AngularJS,Node.js,JQuery
Example 3
In this example, we will provide the negative values as index to extract elements.
<script>
var arr=["AngularJS","Node.js","JQuery","Bootstrap"]
var result=arr.slice(-4,-1);
document.writeln(result);
</script>
Output:
AngularJS,Node.js,JQuery
g. sort() method
The JavaScript array sort() method is used to arrange the array elements in some order. By default,
sort() method follows the ascending order.
Syntax
array.sort(compareFunction)
Parameter
Return
Example 1
<script>
var arr=["AngularJS","Node.js","JQuery","Bootstrap"]
var result=arr.sort();
document.writeln(result);
</script>
Output:
AngularJS,Bootstrap,JQuery,Node.js
Example 2
<script>
var arr=[2,4,1,8,5];
var result=arr.sort();
document.writeln(result);
</script>
Output:
1,2,4,5,8
The sort() method compares all values of the array by passing two values at a time to
the compareFunction. The two parameters a and b represent these two values respectively.
The compareFunction should return a Number. This returned value is used to sort the elements in the
following way:
• If returned value < 0, a is sorted before b (a comes before b).
console.log(names);
Here:
• If a.length - b.length > 0, b comes before a. For example, "Danil" comes after "Ben" as 5 - 3
> 0.
• If a.length - b.length == 0, their position is unchanged. For example, the relative position
of "Jeffrey" and "Fabiano" is unchanged because 7 - 7 == 0.
We can see that this results in the sorting of strings according to their length in ascending order.
Example 4
<script>
var arr=[2,4,1,8,5]
var result=arr.sort(); //1,2,4,5,8
document.writeln(arr[0]);
</script>
Output:
1
Example 5
<script>
var arr=[2,4,1,8,5]
var result=arr.sort().reverse(); // 8,5,4,2,1
document.writeln(arr[0]);
</script>
Output:
8
h. toString() Method
The toString() method is used for converting and representing an array into string form. It returns the
string containing the specified array elements. Commas separate these elements, and the string does not
affect the original array.
Syntax
array.toString()
Parameters
Return
It returns a string that contains all the elements of the specified array.
<!DOCTYPE html>
<html>
<head> <h3>Array Methods</h3> </br>
</head>
<body>
<script>
var arr=['a','b','c','d','e','f','g','h','i','j']; //array elements
var str=arr.toString(); //toString() method implementation
document.write("After converting into string: "+str);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head> <h3>Array Methods</h3> </br>
</head>
<body>
<script>
var season=["Spring","Autumn","Summer","Winter"];
var str=season.toString(); //toString() method implementation
document.write("After converting into string: "+str);
</script>
</body>
</html>
<html>
<head> <h5> Array Methods </h5> </br>
</head>
<body>
<script>
var arr=["1","2","3","4"];
document.write(arr.toString()); //After converting into string.
</script>
</br></br>
</body>
</html>
i. unshift() method
The JavaScript Array unshift() method adds one or more elements to the beginning of an array and
returns the new length of the array.
The syntax of the unshift() method is:
unshift() Parameters
The unshift() method takes in an arbitrary number of elements to add to the array.
• Returns the new (after adding arguments to the beginning of array) length of the array upon
Notes:
Output
j. splice() method
The JavaScript Array splice() method returns an array by changing (adding/removing) its elements in
place.
splice() Parameters
• item1, ..., itemN (optional) - The elements to add to the start index. If not
// removing 3 elements
let removed2 = languages.splice(2, 3);
console.log(removed2); // [ 'Lua', 'Python', 'C' ]
console.log(languages); // [ 'JavaScript', 'Java', 'C++' ]
Output
[ 'Java', 'Lua' ]
[ 'JavaScript', 'Python', 'C', 'C++' ]
[]
[ 'JavaScript', 'Java', 'Lua', 'Python', 'C', 'C++' ]
[ 'Lua', 'Python', 'C' ]
[ 'JavaScript', 'Java', 'C++' ]
• If start > array.length, splice() does not delete anything and starts appending arguments to
• If start < 0, the index is counted from backward (array.length + start). For example, -1 is
Output
[]
["JavaScript", "Python", "Java", "Lua", "C++"]
[ 'C++' ]
["JavaScript", "Python", "Java", "Lua", "Swift", "Scala", "Go"]
• If deleteCount is omitted or is greater than the number of elements left in the array, it deletes
• If deleteCount is 0 or negative, no elements are removed. But, at least one new element
should be specified.
Output
i. By string literal
ii. By string object (using new keyword)
i) BY STRING LITERAL
The string literal is created using double quotes. The syntax of creating string using string literal is
given below:
<script>
var str="This is string literal";
document.write(str);
</script>
Output:
The syntax of creating string object using new keyword is given below:
<script>
var stringname=new String("hello javascript string");
document.write(stringname);
</script>
Output:
a) charAt(index) Method
The JavaScript String charAt() method returns the character at the given index.
<script>
var str="javascript";
document.write(str.charAt(2));
</script>
Output:
b) concat(str) Method
<script>
var s1="javascript ";
var s2="concat example";
var s3=s1.concat(s2);
document.write(s3);
</script>
Output:
c) indexOf(str) Method
The JavaScript String indexOf(str) method returns the index position of the given string.
<script>
var s1="javascript from indexof";
var n=s1.indexOf("from");
document.write(n);
</script>
Output:
11
d) lastIndexOf(str) Method
The JavaScript String lastIndexOf(str) method returns the last index position of the given string.
<script>
var s1="javascript from indexof";
var n=s1.lastIndexOf("java");
document.write(n);
</script>
Output:
16
e) toLowerCase() Method
The JavaScript String toLowerCase() method returns the given string in lowercase letters.
<script>
var s1="JavaScript toLowerCase Example";
var s2=s1.toLowerCase();
document.write(s2);
</script>
Output:
f) toUpperCase() Method
The JavaScript String toUpperCase() method returns the given string in uppercase letters.
<script>
var s1="JavaScript toUpperCase Example";
var s2=s1.toUpperCase();
document.write(s2);
</script>
Output:
The JavaScript String slice(beginIndex, endIndex) method returns the parts of string from given
beginIndex to endIndex. In slice() method, beginIndex is inclusive and endIndex is exclusive.
<script>
var s1="abcdefgh";
var s2=s1.slice(2,5);
document.write(s2);
</script>
Output:
cde
h) trim() Method
The JavaScript String trim() method removes leading and trailing whitespaces from the string.
<script>
var s1=" javascript trim ";
var s2=s1.trim();
document.write(s2);
</script>
Output:
javascript trim
i) split() Method
<script>
var str="This is javascript";
document.write(str.split(" ")); //splits the given string.
</script>
• Event Handling is a software routine that processes actions, such as keystrokes and mouse
movements.
• It is the receipt of an event at some event handler from an event producer and subsequent
processes.
• It takes some kind of appropriate action in response, such as writing to a log, sending an error
or recovery routine or sending a message.
• The event handler may ultimately forward the event to an event consumer.
Event Description
Handler
onAbort It executes when the user aborts loading an image.
onBlur It executes when the input focus leaves the field of a text, textarea or a select option.
onChange It executes when the input focus exits the field after the user modifies its text.
onClick In this, a function is called when an object in a button is clicked, a link is pushed, a
checkbox is checked or an image map is selected. It can return false to cancel the
action.
onError It executes when an error occurs while loading a document or an image.
onFocus It executes when input focus enters the field by tabbing in or by clicking but not
selecting input from the field.
onLoad It executes when a window or image finishes loading.
onMouseOver The JavaScript code is called when the mouse is placed over a specific link or an
object.
onMouseOut The JavaScript code is called when the mouse leaves a specific link or an object.
onReset It executes when the user resets a form by clicking on the reset button.
onSelect It executes when the user selects some of the text within a text or textarea field.
onSubmit It calls when the form is submitted.
15.4. EXAMPLES
15.4.1. MOUSE EVENTS
Button