Movatterモバイル変換


[0]ホーム

URL:


ShahDhruv21, profile picture
Uploaded byShahDhruv21
PPTX, PDF6,191 views

Event In JavaScript

This document discusses JavaScript events and event listeners. It begins with an introduction that defines events as notifications that specific actions occurred, like user or browser actions. Event handlers are scripts that are executed in response to events. Events can be used to trigger JavaScript code that responds to user interactions. The document then provides examples of common event types like onclick, onsubmit, onmouseover, onmouseout, focus, and blur. It also discusses how to add and remove event listeners using addEventListener() and removeEventListener() methods. The document concludes with an example demonstrating how events can be used to change an HTML element in response to user clicks.

Embed presentation

Downloaded 92 times
JAVA SCRIPT EVENTS AND EVENT LISTENERSA. D. PATEL INSTITUTE OF TECHNOLOGYWEB TECHNOLOGY(2160708) : A.Y. 2018-19GUIDED BY:PROF. HEMANSHU A. PATEL(DEPT OF IT, ADIT)PREPARED BY:KUNAL KATHEE.R.NO.:160010116021SHAH DHRUVE.R NO.:160010116053CHINTAN SUDANIE.R.NO.:160010116056PATEL RUSHILE.R.NO.:170014116001B.E. (IT) SEM - VIDEPARTMENT OF INFORMATION TECHNOLOGYA D PATEL INSTITUTE OF TECHNOLOGY (ADIT)NEW VALLABH VIDYANAGAR, ANAND, GUJARAT
2Introduction• 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 writtenover.)• JavaScript events associated with HTML tag attributes which can be used to connect toevent-handlers
3• JavaScript's interaction with HTML is handled through events that occur when the user orthe browser manipulates a page.• When the page loads, it is called an event. When the user clicks a button, that click too is anevent,Other examples include events like pressing any key, closing a window, resizing awindow, etc.• Developers can use these events to execute JavaScript coded responses, which cause buttonsto close windows, messages to be displayed to users, data to be validated, and virtually anyother type of response imaginable.• Events are a part of the Document Object Model DOM Level 3 and every HTML elementcontains a set of events which can trigger JavaScript Code.
4onclick Event Type• This is the most frequently used event type which occurs when a user clicks the left button ofhis 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 button2. When user tabs to the element3. By executing the focus method4. Element get blurred when another element gets focus
5• Event handlers can be specified two ways1. Assigning the event handler script to an event tag attributeonClick = "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.
6Example:<!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>
7onSubmit Event Type• onSubmit is an event that occurs when you try to submit a form. You can put your formvalidation against this event type.• The following Next slide shows how to use onsubmit. Here we are calling a validatefunction before submitting a form data to the webserver. If validate function returns true, theform will be submitted, otherwise it will not submit the data.
8Example:<!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>
9onmouseover and onmouseout• These two event types will help you create nice effects with images or even with text aswell.• The onmouseover event triggers when you bring your mouse over any element and theonmouseout triggers when you move your mouse out from that element.• Try the following example.
10Example:<!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>
11Event List
12Focus & 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]
13addEventListener• The Event Target method addEventListener() sets up a function that will be calledwhenever the specified event is delivered to the target.• Common targets are Element, Document, and Window, but the target may be any object thatsupports events (such as XML Http Request).• addEventListener() works by adding a function or an object that implements Event Listenerto the list of event listeners for the specified event type on the Event Target on which it'scalled.
14Syntaxtarget.addEventListener(type, listener[, options]);target.addEventListener(type, listener[, useCapture]);target.addEventListener(type, listener[, useCapture, wantsUntrusted ]);document.getElementById("myBtn").addEventListener("click", displayDate);
15removeEventListener• The EventTarget.removeEventListener() method removes from the EventTarget an eventlistener previously registered with EventTarget.addEventListener().• The event listener to be removed is identified using a combination of the event type, theevent listener function itself, and various optional options that may affect the matchingprocess; see Matching event listeners for removal.
16Syntaxtarget.removeEventListener(type, listener[, options]);target.removeEventListener(type, listener[, useCapture]);
17Other 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>
18Output[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

Recommended

PDF
JavaScript - Chapter 11 - Events
PPTX
Javascript event handler
PDF
JavaScript - Chapter 4 - Types and Statements
PDF
JavaScript - Chapter 3 - Introduction
PDF
JavaScript - Chapter 7 - Advanced Functions
PDF
JavaScript - Chapter 8 - Objects
PPTX
Java script
PPSX
Javascript variables and datatypes
PDF
javascript objects
PPTX
Lab #2: Introduction to Javascript
PDF
Basics of JavaScript
PPT
Introduction to Javascript
PPTX
Form Validation in JavaScript
PPT
JavaScript & Dom Manipulation
PDF
JavaScript - Chapter 12 - Document Object Model
PPT
JavaScript - An Introduction
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
PDF
JavaScript - Chapter 6 - Basic Functions
PPTX
jQuery
PPTX
Dom(document object model)
PDF
Javascript basics
PPTX
Ajax
PPTX
Presentation of bootstrap
PPT
#"button" role="switch" aria-checked="false" aria-label="Save #" aria-haspopup="dialog" aria-controls=":R6rl69r6:" popovertarget=":R6rl69r6:">
PPTX
Java script
PPTX
PHP FUNCTIONS
PPTX
Javascript 2
PDF
Web 5 | JavaScript Events

More Related Content

PDF
JavaScript - Chapter 11 - Events
PPTX
Javascript event handler
PDF
JavaScript - Chapter 4 - Types and Statements
PDF
JavaScript - Chapter 3 - Introduction
PDF
JavaScript - Chapter 7 - Advanced Functions
PDF
JavaScript - Chapter 8 - Objects
PPTX
Java script
JavaScript - Chapter 11 - Events
Javascript event handler
JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 8 - Objects
Java script

What's hot

PPSX
Javascript variables and datatypes
PDF
javascript objects
PPTX
Lab #2: Introduction to Javascript
PDF
Basics of JavaScript
PPT
Introduction to Javascript
PPTX
Form Validation in JavaScript
PPT
JavaScript & Dom Manipulation
PDF
JavaScript - Chapter 12 - Document Object Model
PPT
JavaScript - An Introduction
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
PDF
JavaScript - Chapter 6 - Basic Functions
PPTX
jQuery
PPTX
Dom(document object model)
PDF
Javascript basics
PPTX
Ajax
PPTX
Presentation of bootstrap
PPT
#"button" role="switch" aria-checked="false" aria-label="Save #" aria-haspopup="dialog" aria-controls=":R3dicla9r6:" popovertarget=":R3dicla9r6:">
PPTX
Java script
PPTX
PHP FUNCTIONS
Javascript variables and datatypes
javascript objects
Lab #2: Introduction to Javascript
Basics of JavaScript
Introduction to Javascript
Form Validation in JavaScript
JavaScript & Dom Manipulation
JavaScript - Chapter 12 - Document Object Model
JavaScript - An Introduction
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 6 - Basic Functions
jQuery
Dom(document object model)
Javascript basics
Ajax
Presentation of bootstrap
#"button" role="switch" aria-checked="false" aria-label="Save #" aria-haspopup="dialog" aria-controls=":R3e9kla9r6:" popovertarget=":R3e9kla9r6:">
Java script
PHP FUNCTIONS

Similar to Event In JavaScript

PPTX
Javascript 2
PDF
Web 5 | JavaScript Events
PPTX
Learn Javascript Basics
PPTX
DHTML - Events & Buttons
PPT
Document_Object_Model_in_javaScript..................................ppt
PPT
Event Programming JavaScript
PPT
javascript Event Handling and introduction to event.ppt
PPTX
Upstate CSCI 450 WebDev Chapter 4
PPS
CS101- Introduction to Computing- Lecture 32
PPTX
types of events in JS
PPTX
JavaScript_Event_Handling_Updated_______
PPTX
JavaScript_Event_Handling_Presentation.pptx
PPTX
5 .java script events
PPTX
javascript-events_zdgdsggdgdgdsggdgdgd.pptx
PPTX
FYBSC IT Web Programming Unit III Events and Event Handlers
PDF
Events.pdf
PPTX
Upstate CSCI 450 WebDev Chapter 9
PPTX
JavaScript_Events.pptx
PPTX
Web programming
PPT
Learn javascript easy steps
Javascript 2
Web 5 | JavaScript Events
Learn Javascript Basics
DHTML - Events & Buttons
Document_Object_Model_in_javaScript..................................ppt
Event Programming JavaScript
javascript Event Handling and introduction to event.ppt
Upstate CSCI 450 WebDev Chapter 4
CS101- Introduction to Computing- Lecture 32
types of events in JS
JavaScript_Event_Handling_Updated_______
JavaScript_Event_Handling_Presentation.pptx
5 .java script events
javascript-events_zdgdsggdgdgdsggdgdgd.pptx
FYBSC IT Web Programming Unit III Events and Event Handlers
Events.pdf
Upstate CSCI 450 WebDev Chapter 9
JavaScript_Events.pptx
Web programming
Learn javascript easy steps

More from ShahDhruv21

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

Recently uploaded

PDF
Structural Conservation Appraisal of Indian Monuments Preserving India’s Arch...
PPTX
ISO 14224 Compliance & CMMS Software — A Comprehensive Guide for Reliable Mai...
PPTX
Optimizing Plant Maintenance — Key Elements of a Successful Maintenance Plan ...
PPTX
Assessment 4 SRS Presentation - Final (2).pptx
PPTX
TPM Metrics & Measurement: Drive Performance Excellence with TPM | MaintWiz
PPTX
Shutdown Maintenance Explained — Full Plant Turnaround & Best Practices with ...
PPTX
UnrealGameplayAbilitySystemPresentation.pptx
PDF
Basic Engineering mechanical handwriting notes
PDF
Hazim Gaber - A Lean Six Sigma Black Belt
PPT
63490613-Boiler-Tube-Leakage-analysis-symptoms-causes.ppt
PPTX
Vertical turbine pump explains installed in power plants
PPTX
Cloud vs On-Premises CMMS — Which Maintenance Platform Is Better for Your Plant?
PPTX
Optimizing Operations: Key Elements of a Successful Plant Maintenance Plan — ...
PPTX
How to Implement Kaizen in Your Organization for Continuous Improvement Success
PPTX
Preventive Maintenance Program for Compressors – Complete Guide
PDF
AI-Driven CTI for Business: Emerging Threats, Attack Strategies, and Defensiv...
PPTX
Network Security v1.0 - Module 2.pptx
PPTX
How to Select the Right CMMS Software for Your Organization — A Complete Buye...
PPTX
Introduction Blockchains and Smart Contracts
PPTX
How to Create an Effective Monthly Maintenance Plan for Reliable Plant Operat...
Structural Conservation Appraisal of Indian Monuments Preserving India’s Arch...
ISO 14224 Compliance & CMMS Software — A Comprehensive Guide for Reliable Mai...
Optimizing Plant Maintenance — Key Elements of a Successful Maintenance Plan ...
Assessment 4 SRS Presentation - Final (2).pptx
TPM Metrics & Measurement: Drive Performance Excellence with TPM | MaintWiz
Shutdown Maintenance Explained — Full Plant Turnaround & Best Practices with ...
UnrealGameplayAbilitySystemPresentation.pptx
Basic Engineering mechanical handwriting notes
Hazim Gaber - A Lean Six Sigma Black Belt
63490613-Boiler-Tube-Leakage-analysis-symptoms-causes.ppt
Vertical turbine pump explains installed in power plants
Cloud vs On-Premises CMMS — Which Maintenance Platform Is Better for Your Plant?
Optimizing Operations: Key Elements of a Successful Plant Maintenance Plan — ...
How to Implement Kaizen in Your Organization for Continuous Improvement Success
Preventive Maintenance Program for Compressors – Complete Guide
AI-Driven CTI for Business: Emerging Threats, Attack Strategies, and Defensiv...
Network Security v1.0 - Module 2.pptx
How to Select the Right CMMS Software for Your Organization — A Complete Buye...
Introduction Blockchains and Smart Contracts
How to Create an Effective Monthly Maintenance Plan for Reliable Plant Operat...

Event In JavaScript

  • 1.
    JAVA SCRIPT EVENTSAND EVENT LISTENERSA. D. PATEL INSTITUTE OF TECHNOLOGYWEB TECHNOLOGY(2160708) : A.Y. 2018-19GUIDED BY:PROF. HEMANSHU A. PATEL(DEPT OF IT, ADIT)PREPARED BY:KUNAL KATHEE.R.NO.:160010116021SHAH DHRUVE.R NO.:160010116053CHINTAN SUDANIE.R.NO.:160010116056PATEL RUSHILE.R.NO.:170014116001B.E. (IT) SEM - VIDEPARTMENT OF INFORMATION TECHNOLOGYA D PATEL INSTITUTE OF TECHNOLOGY (ADIT)NEW VALLABH VIDYANAGAR, ANAND, GUJARAT
  • 2.
    2Introduction• Event-driven: codeexecuted 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 writtenover.)• JavaScript events associated with HTML tag attributes which can be used to connect toevent-handlers
  • 3.
    3• JavaScript's interactionwith HTML is handled through events that occur when the user orthe browser manipulates a page.• When the page loads, it is called an event. When the user clicks a button, that click too is anevent,Other examples include events like pressing any key, closing a window, resizing awindow, etc.• Developers can use these events to execute JavaScript coded responses, which cause buttonsto close windows, messages to be displayed to users, data to be validated, and virtually anyother type of response imaginable.• Events are a part of the Document Object Model DOM Level 3 and every HTML elementcontains a set of events which can trigger JavaScript Code.
  • 4.
    4onclick Event Type•This is the most frequently used event type which occurs when a user clicks the left button ofhis 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 button2. When user tabs to the element3. By executing the focus method4. Element get blurred when another element gets focus
  • 5.
    5• Event handlerscan be specified two ways1. Assigning the event handler script to an event tag attributeonClick = "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.
    6Example:<!DOCTYPE html><html><head><script type="text/javascript"></script></head><body><p>Clickthe following button and see result</p><form><input type="button" onclick="sayHello()" value="Say Hello" /></form></body></html>
  • 7.
    7onSubmit Event Type•onSubmit is an event that occurs when you try to submit a form. You can put your formvalidation against this event type.• The following Next slide shows how to use onsubmit. Here we are calling a validatefunction before submitting a form data to the webserver. If validate function returns true, theform will be submitted, otherwise it will not submit the data.
  • 8.
    8Example:<!DOCTYPE html><html><head><script type="text/javascript"></script></head><body><formmethod="POST" action="target.html" onsubmit="return validate()">.......<input type="submit" value="Submit" /></form></body></html>
  • 9.
    9onmouseover and onmouseout•These two event types will help you create nice effects with images or even with text aswell.• The onmouseover event triggers when you bring your mouse over any element and theonmouseout triggers when you move your mouse out from that element.• Try the following example.
  • 10.
    10Example:<!DOCTYPE html><html><head><script type="text/javascript"></script></head><body><p>Bringyour 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.
  • 12.
    12Focus & BlurEvent 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.
    13addEventListener• The EventTarget method addEventListener() sets up a function that will be calledwhenever the specified event is delivered to the target.• Common targets are Element, Document, and Window, but the target may be any object thatsupports events (such as XML Http Request).• addEventListener() works by adding a function or an object that implements Event Listenerto the list of event listeners for the specified event type on the Event Target on which it'scalled.
  • 14.
    14Syntaxtarget.addEventListener(type, listener[, options]);target.addEventListener(type,listener[, useCapture]);target.addEventListener(type, listener[, useCapture, wantsUntrusted ]);document.getElementById("myBtn").addEventListener("click", displayDate);
  • 15.
    15removeEventListener• The EventTarget.removeEventListener()method removes from the EventTarget an eventlistener previously registered with EventTarget.addEventListener().• The event listener to be removed is identified using a combination of the event type, theevent listener function itself, and various optional options that may affect the matchingprocess; see Matching event listeners for removal.
  • 16.
  • 17.
    17Other Example OfEvents<!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.
    18Output[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.

[8]ページ先頭

©2009-2025 Movatter.jp