SlideShare a Scribd company logo
JAVA SCRIPT EVENTS AND EVENT LISTENERS
A. D. PATEL INSTITUTE OF TECHNOLOGY
WEB TECHNOLOGY(2160708) : A.Y. 2018-19
GUIDED BY:
PROF. HEMANSHU A. PATEL
(DEPT OF IT, ADIT)
PREPARED BY:
KUNAL KATHE
E.R.NO.:160010116021
SHAH DHRUV
E.R NO.:160010116053
CHINTAN SUDANI
E.R.NO.:160010116056
PATEL RUSHIL
E.R.NO.:170014116001
B.E. (IT) SEM - VI
DEPARTMENT OF INFORMATION TECHNOLOGY
A D PATEL INSTITUTE OF TECHNOLOGY (ADIT)
NEW VALLABH VIDYANAGAR, ANAND, GUJARAT
2
Introduction
• Event-driven: code executed resulting to user or browser action.
• Event: a notification that something specific occurred -- by browser or user.
• Event handler: a script implicitly executed in response to event occurrence.
• Registration: the process of connecting event handler to event.
• Events are JavaScript objects --> names are case sensitive, all use lowercase only.
(Method write should never be used in event handler. May cause document to be written
over.)
• JavaScript events associated with HTML tag attributes which can be used to connect to
event-handlers
3
• JavaScript's interaction with HTML is handled through events that occur when the user or
the browser manipulates a page.
• When the page loads, it is called an event. When the user clicks a button, that click too is an
event,Other examples include events like pressing any key, closing a window, resizing a
window, etc.
• Developers can use these events to execute JavaScript coded responses, which cause buttons
to close windows, messages to be displayed to users, data to be validated, and virtually any
other type of response imaginable.
• Events are a part of the Document Object Model DOM Level 3 and every HTML element
contains a set of events which can trigger JavaScript Code.
4
onclick Event Type
• This is the most frequently used event type which occurs when a user clicks the left button of
his mouse. You can put your validation, warning etc., against this event type.
• One attribute can appear in several different tags:
e.g. onClick can be in <a> and <input>
• HTML element get focus:
1. When user puts mouse cursor over it and presses the left button
2. When user tabs to the element
3. By executing the focus method
4. Element get blurred when another element gets focus
5
• Event handlers can be specified two ways
1. Assigning the event handler script to an event tag attribute
onClick = "alert('Mouse click!');"
onClick = "myHandler();
2. Assigning them to properties of JavaScript object associated with HTML elements.
• The load event: the completion of loading of a document by browser
• The onload attribute of <body> used to specify event handler:
• The unload event: used to clean up things before a document is unloaded.
6
Example:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
</script>
</head>
<body>
<p>Click the following button and see result</p>
<form>
<input type="button" onclick="sayHello()" value="Say Hello" />
</form>
</body>
</html>
7
onSubmit Event Type
• onSubmit is an event that occurs when you try to submit a form. You can put your form
validation against this event type.
• The following Next slide shows how to use onsubmit. Here we are calling a validate
function before submitting a form data to the webserver. If validate function returns true, the
form will be submitted, otherwise it will not submit the data.
8
Example:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
</script>
</head>
<body>
<form method="POST" action="target.html" onsubmit="return validate()">
.......
<input type="submit" value="Submit" />
</form>
</body>
</html>
9
onmouseover and onmouseout
• These two event types will help you create nice effects with images or even with text as
well.
• The onmouseover event triggers when you bring your mouse over any element and the
onmouseout triggers when you move your mouse out from that element.
• Try the following example.
10
Example:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
</script>
</head>
<body>
<p>Bring your mouse inside the division to see the result:</p>
<div onmouseover="over()" onmouseout="out()">
<h2> This is inside the division </h2>
</div>
</body>
</html>
11
Event List
12
Focus & Blur Event Example:
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
</head>
<body>
<h1>Hello How Are You...?</h1>
<form>
Click This Button<br/>
<input type="button" value="Click Me!" onclick="myFun()"/><br/>
<input type="text" id="username" onfocus="this.blur()"/><br/>
</form>
<script type="text/javascript">
function myFun()
{
document.getElementById("username").value="Dhruv";
}
</script>
</body>
</html>
[fig.1 Before Click On That Button]
[fig.2 After Click On That Button]
13
addEventListener
• The Event Target method addEventListener() sets up a function that will be called
whenever the specified event is delivered to the target.
• Common targets are Element, Document, and Window, but the target may be any object that
supports events (such as XML Http Request).
• addEventListener() works by adding a function or an object that implements Event Listener
to the list of event listeners for the specified event type on the Event Target on which it's
called.
14
Syntax
target.addEventListener(type, listener[, options]);
target.addEventListener(type, listener[, useCapture]);
target.addEventListener(type, listener[, useCapture, wantsUntrusted ]);
document.getElementById("myBtn").addEventListener("click", displayDate);
15
removeEventListener
• The EventTarget.removeEventListener() method removes from the EventTarget an event
listener previously registered with EventTarget.addEventListener().
• The event listener to be removed is identified using a combination of the event type, the
event listener function itself, and various optional options that may affect the matching
process; see Matching event listeners for removal.
16
Syntax
target.removeEventListener(type, listener[, options]);
target.removeEventListener(type, listener[, useCapture]);
17
Other Example Of Events
<!DOCTYPE html>
<html>
<head><title>Display Page</title></head>
<body>
<hr color="orange" />
<center><h1 id="htag">Welcome To ADIT</h1></center>
<hr color="blue" />
<center><button type="button" onclick="Change()">Change</button>
<button type="button" onclick="Hide()">Hide</button>
<button type="button" onclick="Display()">Display</button>
<button type="button" onclick="ChangeColor()">Color Change</button></center>
<hr color="green" />
<script type="text/javascript">
function Change()
{ document.getElementById("htag").innerHTML="Welcome ABC"; }
function Display()
{ document.getElementById("htag").style.display="block"; }
function Hide()
{ document.getElementById("htag").style.display="none"; }
function ChangeColor()
{ document.getElementById("htag").style.color="blue"; }
</script>
</body>
</html>
18
Output
[fig.3 Initial Page] [fig.4 When Click On Change Or Display]
[fig.5 When Click On Hide] [fig.6 When Click On Color Change]
19

More Related Content

What's hot

Js ppt
Js pptJs ppt
Js ppt
Rakhi Thota
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
Fahim Abdullah
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Andres Baravalle
 
Java script
Java scriptJava script
Java script
Abhishek Kesharwani
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
Ravinder Kamboj
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
Jeff Fox
 
Document Object Model
Document Object ModelDocument Object Model
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
Gil Fink
 
javascript objects
javascript objectsjavascript objects
javascript objects
Vijay Kalyan
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Arulmurugan Rajaraman
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
Jalpesh Vasa
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
abhilashagupta
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overview
Jacob Nelson
 
Javascript
JavascriptJavascript
Javascript
guest03a6e6
 
JavaScript: Events Handling
JavaScript: Events HandlingJavaScript: Events Handling
JavaScript: Events Handling
Yuriy Bezgachnyuk
 

What's hot (20)

Js ppt
Js pptJs ppt
Js ppt
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Java script
Java scriptJava script
Java script
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overview
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript: Events Handling
JavaScript: Events HandlingJavaScript: Events Handling
JavaScript: Events Handling
 

Similar to Event In JavaScript

types of events in JS
types of events in JS types of events in JS
types of events in JS
chauhankapil
 
5 .java script events
5 .java script   events5 .java script   events
5 .java script events
chauhankapil
 
Javascript Browser Events.pdf
Javascript Browser Events.pdfJavascript Browser Events.pdf
Javascript Browser Events.pdf
ShubhamChaurasia88
 
Web programming
Web programmingWeb programming
Web programming
Subha Selvam
 
Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9
DanWooster1
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
PERKYTORIALS
 
jQuery
jQueryjQuery
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
Brian Moschel
 
DHTML - Events & Buttons
DHTML - Events  & ButtonsDHTML - Events  & Buttons
DHTML - Events & Buttons
Deep Patel
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
AnamikaRai59
 
Client Web
Client WebClient Web
Client Web
Markiyan Matsekh
 
Javascript #8 : événements
Javascript #8 : événementsJavascript #8 : événements
Javascript #8 : événements
Jean Michel
 
Caliburn.micro jump start composite applications for WPF, Silverlight and WP7
Caliburn.micro jump start composite applications for WPF, Silverlight and WP7Caliburn.micro jump start composite applications for WPF, Silverlight and WP7
Caliburn.micro jump start composite applications for WPF, Silverlight and WP7
Igor Moochnick
 
Event
EventEvent
Event
mussawir20
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementation
davejohnson
 
JavaScript-L20.pptx
JavaScript-L20.pptxJavaScript-L20.pptx
JavaScript-L20.pptx
VivekBaghel30
 
Sperimentazioni lezione6 from_designtoapplication copy
Sperimentazioni lezione6 from_designtoapplication copySperimentazioni lezione6 from_designtoapplication copy
Sperimentazioni lezione6 from_designtoapplication copy
Salvatore Iaconesi
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
maamir farooq
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
maamir farooq
 
Less03 2 e_testermodule_2
Less03 2 e_testermodule_2Less03 2 e_testermodule_2
Less03 2 e_testermodule_2
Suresh Mishra
 

Similar to Event In JavaScript (20)

types of events in JS
types of events in JS types of events in JS
types of events in JS
 
5 .java script events
5 .java script   events5 .java script   events
5 .java script events
 
Javascript Browser Events.pdf
Javascript Browser Events.pdfJavascript Browser Events.pdf
Javascript Browser Events.pdf
 
Web programming
Web programmingWeb programming
Web programming
 
Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
jQuery
jQueryjQuery
jQuery
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
 
DHTML - Events & Buttons
DHTML - Events  & ButtonsDHTML - Events  & Buttons
DHTML - Events & Buttons
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
Client Web
Client WebClient Web
Client Web
 
Javascript #8 : événements
Javascript #8 : événementsJavascript #8 : événements
Javascript #8 : événements
 
Caliburn.micro jump start composite applications for WPF, Silverlight and WP7
Caliburn.micro jump start composite applications for WPF, Silverlight and WP7Caliburn.micro jump start composite applications for WPF, Silverlight and WP7
Caliburn.micro jump start composite applications for WPF, Silverlight and WP7
 
Event
EventEvent
Event
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementation
 
JavaScript-L20.pptx
JavaScript-L20.pptxJavaScript-L20.pptx
JavaScript-L20.pptx
 
Sperimentazioni lezione6 from_designtoapplication copy
Sperimentazioni lezione6 from_designtoapplication copySperimentazioni lezione6 from_designtoapplication copy
Sperimentazioni lezione6 from_designtoapplication copy
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
 
Less03 2 e_testermodule_2
Less03 2 e_testermodule_2Less03 2 e_testermodule_2
Less03 2 e_testermodule_2
 

More from ShahDhruv21

Semantic net in AI
Semantic net in AISemantic net in AI
Semantic net in AI
ShahDhruv21
 
Error Detection & Error Correction Codes
Error Detection & Error Correction CodesError Detection & Error Correction Codes
Error Detection & Error Correction Codes
ShahDhruv21
 
Secure Hash Algorithm (SHA)
Secure Hash Algorithm (SHA)Secure Hash Algorithm (SHA)
Secure Hash Algorithm (SHA)
ShahDhruv21
 
Data Mining in Health Care
Data Mining in Health CareData Mining in Health Care
Data Mining in Health Care
ShahDhruv21
 
Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs
ShahDhruv21
 
MongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shellMongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shell
ShahDhruv21
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
ShahDhruv21
 
Interpreter
InterpreterInterpreter
Interpreter
ShahDhruv21
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
ShahDhruv21
 
Pyramid Vector Quantization
Pyramid Vector QuantizationPyramid Vector Quantization
Pyramid Vector Quantization
ShahDhruv21
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
ShahDhruv21
 
WaterFall Model & Spiral Mode
WaterFall Model & Spiral ModeWaterFall Model & Spiral Mode
WaterFall Model & Spiral Mode
ShahDhruv21
 

More from ShahDhruv21 (12)

Semantic net in AI
Semantic net in AISemantic net in AI
Semantic net in AI
 
Error Detection & Error Correction Codes
Error Detection & Error Correction CodesError Detection & Error Correction Codes
Error Detection & Error Correction Codes
 
Secure Hash Algorithm (SHA)
Secure Hash Algorithm (SHA)Secure Hash Algorithm (SHA)
Secure Hash Algorithm (SHA)
 
Data Mining in Health Care
Data Mining in Health CareData Mining in Health Care
Data Mining in Health Care
 
Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs
 
MongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shellMongoDB installation,CRUD operation & JavaScript shell
MongoDB installation,CRUD operation & JavaScript shell
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
 
Interpreter
InterpreterInterpreter
Interpreter
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
 
Pyramid Vector Quantization
Pyramid Vector QuantizationPyramid Vector Quantization
Pyramid Vector Quantization
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
 
WaterFall Model & Spiral Mode
WaterFall Model & Spiral ModeWaterFall Model & Spiral Mode
WaterFall Model & Spiral Mode
 

Recently uploaded

Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
Atif Razi
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
riddhimaagrawal986
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
bijceesjournal
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
IJECEIAES
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 

Recently uploaded (20)

Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 

Event In JavaScript

  • 1. JAVA SCRIPT EVENTS AND EVENT LISTENERS A. D. PATEL INSTITUTE OF TECHNOLOGY WEB TECHNOLOGY(2160708) : A.Y. 2018-19 GUIDED BY: PROF. HEMANSHU A. PATEL (DEPT OF IT, ADIT) PREPARED BY: KUNAL KATHE E.R.NO.:160010116021 SHAH DHRUV E.R NO.:160010116053 CHINTAN SUDANI E.R.NO.:160010116056 PATEL RUSHIL E.R.NO.:170014116001 B.E. (IT) SEM - VI DEPARTMENT OF INFORMATION TECHNOLOGY A D PATEL INSTITUTE OF TECHNOLOGY (ADIT) NEW VALLABH VIDYANAGAR, ANAND, GUJARAT
  • 2. 2 Introduction • Event-driven: code executed resulting to user or browser action. • Event: a notification that something specific occurred -- by browser or user. • Event handler: a script implicitly executed in response to event occurrence. • Registration: the process of connecting event handler to event. • Events are JavaScript objects --> names are case sensitive, all use lowercase only. (Method write should never be used in event handler. May cause document to be written over.) • JavaScript events associated with HTML tag attributes which can be used to connect to event-handlers
  • 3. 3 • JavaScript's interaction with HTML is handled through events that occur when the user or the browser manipulates a page. • When the page loads, it is called an event. When the user clicks a button, that click too is an event,Other examples include events like pressing any key, closing a window, resizing a window, etc. • Developers can use these events to execute JavaScript coded responses, which cause buttons to close windows, messages to be displayed to users, data to be validated, and virtually any other type of response imaginable. • Events are a part of the Document Object Model DOM Level 3 and every HTML element contains a set of events which can trigger JavaScript Code.
  • 4. 4 onclick Event Type • This is the most frequently used event type which occurs when a user clicks the left button of his mouse. You can put your validation, warning etc., against this event type. • One attribute can appear in several different tags: e.g. onClick can be in <a> and <input> • HTML element get focus: 1. When user puts mouse cursor over it and presses the left button 2. When user tabs to the element 3. By executing the focus method 4. Element get blurred when another element gets focus
  • 5. 5 • Event handlers can be specified two ways 1. Assigning the event handler script to an event tag attribute onClick = "alert('Mouse click!');" onClick = "myHandler(); 2. Assigning them to properties of JavaScript object associated with HTML elements. • The load event: the completion of loading of a document by browser • The onload attribute of <body> used to specify event handler: • The unload event: used to clean up things before a document is unloaded.
  • 6. 6 Example: <!DOCTYPE html> <html> <head> <script type="text/javascript"> </script> </head> <body> <p>Click the following button and see result</p> <form> <input type="button" onclick="sayHello()" value="Say Hello" /> </form> </body> </html>
  • 7. 7 onSubmit Event Type • onSubmit is an event that occurs when you try to submit a form. You can put your form validation against this event type. • The following Next slide shows how to use onsubmit. Here we are calling a validate function before submitting a form data to the webserver. If validate function returns true, the form will be submitted, otherwise it will not submit the data.
  • 8. 8 Example: <!DOCTYPE html> <html> <head> <script type="text/javascript"> </script> </head> <body> <form method="POST" action="target.html" onsubmit="return validate()"> ....... <input type="submit" value="Submit" /> </form> </body> </html>
  • 9. 9 onmouseover and onmouseout • These two event types will help you create nice effects with images or even with text as well. • The onmouseover event triggers when you bring your mouse over any element and the onmouseout triggers when you move your mouse out from that element. • Try the following example.
  • 10. 10 Example: <!DOCTYPE html> <html> <head> <script type="text/javascript"> </script> </head> <body> <p>Bring your mouse inside the division to see the result:</p> <div onmouseover="over()" onmouseout="out()"> <h2> This is inside the division </h2> </div> </body> </html>
  • 12. 12 Focus & Blur Event Example: <!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Hello How Are You...?</h1> <form> Click This Button<br/> <input type="button" value="Click Me!" onclick="myFun()"/><br/> <input type="text" id="username" onfocus="this.blur()"/><br/> </form> <script type="text/javascript"> function myFun() { document.getElementById("username").value="Dhruv"; } </script> </body> </html> [fig.1 Before Click On That Button] [fig.2 After Click On That Button]
  • 13. 13 addEventListener • The Event Target method addEventListener() sets up a function that will be called whenever the specified event is delivered to the target. • Common targets are Element, Document, and Window, but the target may be any object that supports events (such as XML Http Request). • addEventListener() works by adding a function or an object that implements Event Listener to the list of event listeners for the specified event type on the Event Target on which it's called.
  • 14. 14 Syntax target.addEventListener(type, listener[, options]); target.addEventListener(type, listener[, useCapture]); target.addEventListener(type, listener[, useCapture, wantsUntrusted ]); document.getElementById("myBtn").addEventListener("click", displayDate);
  • 15. 15 removeEventListener • The EventTarget.removeEventListener() method removes from the EventTarget an event listener previously registered with EventTarget.addEventListener(). • The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.
  • 17. 17 Other Example Of Events <!DOCTYPE html> <html> <head><title>Display Page</title></head> <body> <hr color="orange" /> <center><h1 id="htag">Welcome To ADIT</h1></center> <hr color="blue" /> <center><button type="button" onclick="Change()">Change</button> <button type="button" onclick="Hide()">Hide</button> <button type="button" onclick="Display()">Display</button> <button type="button" onclick="ChangeColor()">Color Change</button></center> <hr color="green" /> <script type="text/javascript"> function Change() { document.getElementById("htag").innerHTML="Welcome ABC"; } function Display() { document.getElementById("htag").style.display="block"; } function Hide() { document.getElementById("htag").style.display="none"; } function ChangeColor() { document.getElementById("htag").style.color="blue"; } </script> </body> </html>
  • 18. 18 Output [fig.3 Initial Page] [fig.4 When Click On Change Or Display] [fig.5 When Click On Hide] [fig.6 When Click On Color Change]
  • 19. 19