SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
Javascript event handler
JAVASCRIPT EVENTS
• Javascript-enabled Web pages are typically event
  driven. Events are actions that occur on the Web page.
  Generally speaking they occur when.
• Your browser does something such as loading or
  unloading a page.
• You do something like clicking a button, moving your
  mouse over a link, or moving your cursor into or out a
  form element.
• If these events which cause JavaScript code to spring
  into action. Each JavaScript event has a corresponding
  event handler that is charged with the responsibility of
  automatically responding to it when it occurs.
     Reference: http://www.wvu.edu˜ support/training/classmat/js/
EVENT HANDLERS
• Event handlers execute JavaScript code to respond to
  events whenever they occur.
• They what makes JavaScript so useful in creating
  interactive Web sites.

  Understanding "event handlers" in JavaScript
• So, what are event handlers? Very powerful and
  useful! They are JavaScript code that are not added
  inside the <script> tags, but rather, inside the html
  tags, that execute JavaScript when something
  happens, such as pressing a button, moving your
  mouse over a link, submitting a form etc. The basic
  syntax of these event handlers is:
                     Reference: Copyright © 1997-2012 JavaScript Kit.
Event Handlers can be divided into two parts:

• interactive Event Handlers and
• non-interactive Event Handlers
• An interactive Event Handler is the one that
  depends on the user interactivity with the form
  or the document. For example, onMouseOver is
  an interactive Event Handler because it depends
  on the users action with the mouse.
• On the other hand non-interactive Event Handler
  would be onLoad, because this Event Handler
  would automatically execute JavaScript code
  without the user's interactivity.
EVENT HANDLERS
Event Handler                         Event that it handles
onBlur          User has left the focus of the object. For example, they clicked
                away from a text field that was previously selected.

onChange        User has changed the object, then attempts to leave that field
                (i.e. clicks elsewhere).

onClick         User clicked on the object.
onDblClick      User clicked twice on the object.
onFocus         User brought the focus to the object (i.e. clicked on it/tabbed to
                it)
onKeydown       A key was pressed over an element.
onKeyup         A key was released over an element.
onKeypress      A key was pressed over an element then released.
onLoad          The object has loaded.                    Reference: quackit.com
Event Handler                 Event that it handles
onMousedown         The cursor moved over the object and
                    mouse/pointing device was pressed down.
onMouseup           The mouse/pointing device was released after being
                    pressed down.
onMouseover         The cursor moved over the object (i.e. user hovers the
                    mouse over the object).
onMousemove         The cursor moved while hovering over an object.

onMouseout          The cursor moved off the object
onReset             User has reset a form.
onSelect            User selected some or all of the contents of the
                    object. For example, the user selected some text
                    within a text field.
onSubmit            User submitted a form.
onUnload            User left the window (i.e. user closes the browser
                    window).
<HTML><HEAD>                                        Browser ‘s Output
<TITLE>Example of onBlur Event Handler</TITLE>
<SCRIPT>
function validateAnswer(answer) {
if (answer == "Brendan Eich")
{alert("Your answer is correct");}
else
{alert("Your answer is wrong") }
}
</SCRIPT></HEAD><BODY>
<H3> Example of onBlur Event Handler</H3>
Who created the JavaScript?:<BR>
<FORM>                              In this example, 'data' is a text field. When a
    <INPUT TYPE="text"              user attempts to leave the field,
     onBlur="validate(this.value)"> the onBlur Event Handler calls the valid()
</FORM>                             function to confirm that 'data' has a legal
</BODY>                             value. Note that the keyword this is used to
                                    refer to the current object.
</HTML>
<HTML><HEAD>                                     Browser’s Output
<TITLE>Example of onChange Event
Handler</TITLE>
<SCRIPT>
function valid(input)
{ alert("You have changed the value from Jesus
    to " + input);}
</SCRIPT>
</HEAD>
<BODY>
<H3>Example of onChange Event
Handler</H3>
Try changing the value from Jesus to something
    else:<BR>                                    In this example, 'data' is a text field.
<FORM>                                           When a user attempts to leave the
                                                 field after a change of the original
<INPUT TYPE="text“
                                                 value, the onChange Event Handler
VALUE=“Jesus" onChange="valid(this.value)“/>     calls the valid() function which alerts
    </FORM></BODY></HTML>                        the user about value that has been
                                                 inputted.
<HTML>                                 Browser’s Output
<HEAD><TITLE>Example of on Focus
   Event Handler</TITLE>
</HEAD>
<BODY>
<H3>Example of onFocus Event
   Handler</H3>
Click your mouse in the textbox:<BR>
<FORM>
<INPUT TYPE="text"
                                        In the above
onFocus='alert("You focused in the
   textbox!!")'>
                                        example, when you
                                        put your mouse on
</FORM>
                                        the text box,
</BODY>
                                        an alert() message
</HTML>
                                        displays a message.
<IMG SRC="images/object.gif"
  NAME="jsobjects"
   onLoad="alert('You loaded my image')">
  Browser’s Output
                         An onLoad event occurs
                         when a window or
                         image finishes loading.
                         For windows, this Event
                         Handler is specified in
                         the <BODY> attribute of
                         the window. In an image,
                         the Event Handler will
                         execute handler text
                         when the image is
                         loaded.
<html><head><script>                                  Browser’s Output
function bigImg(x)
{
x.style.height="64px";
x.style.width="64px";
}
function normalImg(x)
{
x.style.height="32px";
x.style.width="32px";
}
</script></head><body>

<img onmouseover="bigImg(this)"
   onmouseout="normalImg(this)" border="0"
   src="grasshopper.gif" alt=“Grasshopper"
   width="32" height="32">

<p>The function bigImg() is triggered when the user
   moves the mouse pointer over the image.</p>
<p>The function normalImg() is triggered when the
   mouse pointer is moved out of the image.</p>
</body></html>
Browser’s Output
•   <script>
•   function myFunction()
•   {
•   alert("You have selected
    some text!");
•   }
•   </script>
•   </head>
•   <body>

• Some text: <input
  type="text" value="Hello
  world!"                      On the above example, when the
                               value of the textbox was selected
  onselect="myFunction()">     an alert box displays a message
MATCHING TYPE: Match Column A to Column B. Write
          your answer on the space provided.
                      COLUMN A                                    COLUMN B
                  Event that it handles                          Event Handler

_________1. The cursor moved over the object and            a.   onChange
mouse/pointing device was pressed down.                     b.   onClick
_________2. The cursor moved over the object.               c.   onDblClick
_________3. User submitted a form.                          d.   onLoad
_________4. User clicked on the object.                     e.   onMousedown
_________5. The object has loaded.                          f.   onMouseover
_________6. User has changed the object, then attempts      g.   onMouseout
to leave that field (i.e. clicks elsewhere).                h.   onReset
_________7. The cursor moved off the object.                i.   onSelect
_________8. User has reset a form.                          j.   onSubmit
_________9. User clicked twice on the object.
_________10. User selected some or all of the contents of
the object.

More Related Content

PPSX
JDBC: java DataBase connectivity
PDF
JavaScript - Chapter 12 - Document Object Model
PDF
Experience Certificate (KHARAFI)
PPTX
Blood supply of heart
PPTX
Apiculture ppt
PPTX
Operators in java presentation
PPTX
Event In JavaScript
PPT
Social Network Analysis
JDBC: java DataBase connectivity
JavaScript - Chapter 12 - Document Object Model
Experience Certificate (KHARAFI)
Blood supply of heart
Apiculture ppt
Operators in java presentation
Event In JavaScript
Social Network Analysis

What's hot (20)

PPTX
Java script errors &amp; exceptions handling
PPT
JavaScript: Events Handling
PDF
JavaScript - Chapter 11 - Events
PDF
Basics of JavaScript
PPTX
HTML Forms
PPTX
Complete Lecture on Css presentation
PPSX
Javascript variables and datatypes
PDF
Introduction to HTML5
PPT
Introduction to JavaScript
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
PPTX
Java script
PPTX
Javascript operators
PDF
Asp.net state management
ODP
Introduction of Html/css/js
PPTX
Javascript 101
PPTX
PPTX
Loops PHP 04
PPTX
Dom(document object model)
PDF
JavaScript - Chapter 14 - Form Handling
PPT
JavaScript Variables
Java script errors &amp; exceptions handling
JavaScript: Events Handling
JavaScript - Chapter 11 - Events
Basics of JavaScript
HTML Forms
Complete Lecture on Css presentation
Javascript variables and datatypes
Introduction to HTML5
Introduction to JavaScript
JavaScript - Chapter 13 - Browser Object Model(BOM)
Java script
Javascript operators
Asp.net state management
Introduction of Html/css/js
Javascript 101
Loops PHP 04
Dom(document object model)
JavaScript - Chapter 14 - Form Handling
JavaScript Variables
Ad

Similar to Javascript event handler (20)

PPTX
Unit3.pptx
PDF
JavaScript
PDF
JavaScript
PPTX
DHTML - Events & Buttons
PDF
Java script browser objects 1
 
PPTX
Presentation
PPTX
Lab #2: Introduction to Javascript
PPTX
Javascript 2
PPTX
JavaScript_Events.pptx
PPTX
Web programming
PDF
PPTX
Android 3
PPTX
Upstate CSCI 450 WebDev Chapter 9
KEY
Reacting to a Virtual World
PPTX
unit4 wp.pptxjvlbpuvghuigv8ytg2ugvugvuygv
PPTX
types of events in JS
PPTX
5 .java script events
PDF
Javascript #8 : événements
PPTX
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
PPTX
JS basics
Unit3.pptx
JavaScript
JavaScript
DHTML - Events & Buttons
Java script browser objects 1
 
Presentation
Lab #2: Introduction to Javascript
Javascript 2
JavaScript_Events.pptx
Web programming
Android 3
Upstate CSCI 450 WebDev Chapter 9
Reacting to a Virtual World
unit4 wp.pptxjvlbpuvghuigv8ytg2ugvugvuygv
types of events in JS
5 .java script events
Javascript #8 : événements
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
JS basics
Ad

More from Jesus Obenita Jr. (20)

PPTX
Organization and management 3 a Evolution of Management Theory
PPTX
Organization and management 2 Management Function
PPTX
Organization and management 1
PPTX
Designing web page marquee and img tag
PPTX
Ms excel 2013 formatting worksheets
PPTX
Ms excel 2013 data management
PPTX
Microsoft Excel introduction
PPTX
Word 2013 working with pictures
PPTX
Word 2013 Formatting Page
PPTX
Word 2013 8
PPTX
Ms word 2013 7
PPTX
Ms word 2013 6
PPTX
Ms word 2013 4
PPTX
Ms word 2013 2
PPTX
Ms word 2013
PPTX
Parts of the ms word 2013 screen and
PPTX
Word processor
PPT
Session 2 test construction.mt's
PPTX
Cooking ingredients
PPTX
Color theory
Organization and management 3 a Evolution of Management Theory
Organization and management 2 Management Function
Organization and management 1
Designing web page marquee and img tag
Ms excel 2013 formatting worksheets
Ms excel 2013 data management
Microsoft Excel introduction
Word 2013 working with pictures
Word 2013 Formatting Page
Word 2013 8
Ms word 2013 7
Ms word 2013 6
Ms word 2013 4
Ms word 2013 2
Ms word 2013
Parts of the ms word 2013 screen and
Word processor
Session 2 test construction.mt's
Cooking ingredients
Color theory

Recently uploaded (20)

PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Lesson notes of climatology university.
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
RMMM.pdf make it easy to upload and study
PPTX
Cell Types and Its function , kingdom of life
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Lesson notes of climatology university.
human mycosis Human fungal infections are called human mycosis..pptx
Complications of Minimal Access Surgery at WLH
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Module 4: Burden of Disease Tutorial Slides S2 2025
Supply Chain Operations Speaking Notes -ICLT Program
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
VCE English Exam - Section C Student Revision Booklet
O7-L3 Supply Chain Operations - ICLT Program
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Anesthesia in Laparoscopic Surgery in India
Final Presentation General Medicine 03-08-2024.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
RMMM.pdf make it easy to upload and study
Cell Types and Its function , kingdom of life
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
A systematic review of self-coping strategies used by university students to ...

Javascript event handler

  • 2. JAVASCRIPT EVENTS • Javascript-enabled Web pages are typically event driven. Events are actions that occur on the Web page. Generally speaking they occur when. • Your browser does something such as loading or unloading a page. • You do something like clicking a button, moving your mouse over a link, or moving your cursor into or out a form element. • If these events which cause JavaScript code to spring into action. Each JavaScript event has a corresponding event handler that is charged with the responsibility of automatically responding to it when it occurs. Reference: http://www.wvu.edu˜ support/training/classmat/js/
  • 3. EVENT HANDLERS • Event handlers execute JavaScript code to respond to events whenever they occur. • They what makes JavaScript so useful in creating interactive Web sites. Understanding "event handlers" in JavaScript • So, what are event handlers? Very powerful and useful! They are JavaScript code that are not added inside the <script> tags, but rather, inside the html tags, that execute JavaScript when something happens, such as pressing a button, moving your mouse over a link, submitting a form etc. The basic syntax of these event handlers is: Reference: Copyright © 1997-2012 JavaScript Kit.
  • 4. Event Handlers can be divided into two parts: • interactive Event Handlers and • non-interactive Event Handlers • An interactive Event Handler is the one that depends on the user interactivity with the form or the document. For example, onMouseOver is an interactive Event Handler because it depends on the users action with the mouse. • On the other hand non-interactive Event Handler would be onLoad, because this Event Handler would automatically execute JavaScript code without the user's interactivity.
  • 5. EVENT HANDLERS Event Handler Event that it handles onBlur User has left the focus of the object. For example, they clicked away from a text field that was previously selected. onChange User has changed the object, then attempts to leave that field (i.e. clicks elsewhere). onClick User clicked on the object. onDblClick User clicked twice on the object. onFocus User brought the focus to the object (i.e. clicked on it/tabbed to it) onKeydown A key was pressed over an element. onKeyup A key was released over an element. onKeypress A key was pressed over an element then released. onLoad The object has loaded. Reference: quackit.com
  • 6. Event Handler Event that it handles onMousedown The cursor moved over the object and mouse/pointing device was pressed down. onMouseup The mouse/pointing device was released after being pressed down. onMouseover The cursor moved over the object (i.e. user hovers the mouse over the object). onMousemove The cursor moved while hovering over an object. onMouseout The cursor moved off the object onReset User has reset a form. onSelect User selected some or all of the contents of the object. For example, the user selected some text within a text field. onSubmit User submitted a form. onUnload User left the window (i.e. user closes the browser window).
  • 7. <HTML><HEAD> Browser ‘s Output <TITLE>Example of onBlur Event Handler</TITLE> <SCRIPT> function validateAnswer(answer) { if (answer == "Brendan Eich") {alert("Your answer is correct");} else {alert("Your answer is wrong") } } </SCRIPT></HEAD><BODY> <H3> Example of onBlur Event Handler</H3> Who created the JavaScript?:<BR> <FORM> In this example, 'data' is a text field. When a <INPUT TYPE="text" user attempts to leave the field, onBlur="validate(this.value)"> the onBlur Event Handler calls the valid() </FORM> function to confirm that 'data' has a legal </BODY> value. Note that the keyword this is used to refer to the current object. </HTML>
  • 8. <HTML><HEAD> Browser’s Output <TITLE>Example of onChange Event Handler</TITLE> <SCRIPT> function valid(input) { alert("You have changed the value from Jesus to " + input);} </SCRIPT> </HEAD> <BODY> <H3>Example of onChange Event Handler</H3> Try changing the value from Jesus to something else:<BR> In this example, 'data' is a text field. <FORM> When a user attempts to leave the field after a change of the original <INPUT TYPE="text“ value, the onChange Event Handler VALUE=“Jesus" onChange="valid(this.value)“/> calls the valid() function which alerts </FORM></BODY></HTML> the user about value that has been inputted.
  • 9. <HTML> Browser’s Output <HEAD><TITLE>Example of on Focus Event Handler</TITLE> </HEAD> <BODY> <H3>Example of onFocus Event Handler</H3> Click your mouse in the textbox:<BR> <FORM> <INPUT TYPE="text" In the above onFocus='alert("You focused in the textbox!!")'> example, when you put your mouse on </FORM> the text box, </BODY> an alert() message </HTML> displays a message.
  • 10. <IMG SRC="images/object.gif" NAME="jsobjects" onLoad="alert('You loaded my image')"> Browser’s Output An onLoad event occurs when a window or image finishes loading. For windows, this Event Handler is specified in the <BODY> attribute of the window. In an image, the Event Handler will execute handler text when the image is loaded.
  • 11. <html><head><script> Browser’s Output function bigImg(x) { x.style.height="64px"; x.style.width="64px"; } function normalImg(x) { x.style.height="32px"; x.style.width="32px"; } </script></head><body> <img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="grasshopper.gif" alt=“Grasshopper" width="32" height="32"> <p>The function bigImg() is triggered when the user moves the mouse pointer over the image.</p> <p>The function normalImg() is triggered when the mouse pointer is moved out of the image.</p> </body></html>
  • 12. Browser’s Output • <script> • function myFunction() • { • alert("You have selected some text!"); • } • </script> • </head> • <body> • Some text: <input type="text" value="Hello world!" On the above example, when the value of the textbox was selected onselect="myFunction()"> an alert box displays a message
  • 13. MATCHING TYPE: Match Column A to Column B. Write your answer on the space provided. COLUMN A COLUMN B Event that it handles Event Handler _________1. The cursor moved over the object and a. onChange mouse/pointing device was pressed down. b. onClick _________2. The cursor moved over the object. c. onDblClick _________3. User submitted a form. d. onLoad _________4. User clicked on the object. e. onMousedown _________5. The object has loaded. f. onMouseover _________6. User has changed the object, then attempts g. onMouseout to leave that field (i.e. clicks elsewhere). h. onReset _________7. The cursor moved off the object. i. onSelect _________8. User has reset a form. j. onSubmit _________9. User clicked twice on the object. _________10. User selected some or all of the contents of the object.