GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.tutorialrepublic.com — Event Handling in JavaScript - Tutorial Republic JAVASCRIPT BASIC
JS Introduction
JS Getting Started
JS Syntax
JS Variables
JS Generating Output
JS Data Types
JS Operators
JS Events
JS Strings
JS Numbers
JS If…Else
JS Switch…Case
JS Arrays
JS Sorting Arrays
JS Loops
JS Functions
JS Objects
JAVASCRIPT & DOM
JS DOM Nodes
JS DOM Selectors
JS DOM Styling
JS DOM Get Set Attributes
JS DOM Manipulation
JS DOM Navigation
JAVASCRIPT & BOM
JAVASCRIPT ADVANCED
JS Date and Time
JS Math Operations
JS Type Conversions
JS Event Listeners
JS Event Propagation
JS Borrowing Methods
JS Hoisting Behavior
JS Closures
JS Strict Mode
JS JSON Parsing
JS Error Handling
JS Regular Expressions
JS Form Validation
JS Cookies
JS AJAX Requests
JS ES6 Features
JAVASCRIPT EXAMPLES
JAVASCRIPT REFERENCE
Advertisements
JavaScript EventsIn this tutorial you will learn how to handle events in JavaScript. Understanding Events and Event HandlersAn event is something that happens when user interact with the web page, such as when he clicked a link or button, entered text into an input box or textarea, made selection in a select box, pressed key on the keyboard, moved the mouse pointer, submits a form, etc. In some cases, the Browser itself can trigger the events, such as the page load and unload events. When an event occur, you can use a JavaScript event handler (or an event listener) to detect them and perform specific task or set of tasks. By convention, the names for event handlers always begin with the word "on", so an event handler for the click event is called There are several ways to assign an event handler. The simplest way is to add them directly to the start tag of the HTML elements using the special event-handler attributes. For example, to assign a click handler for a button element, we can use ExampleTry this code »
However, to keep the JavaScript seperate from HTML, you can set up the event handler in an external JavaScript file or within the ExampleTry this code »
Note: Since HTML attributes are case-insensitive so In general, the events can be categorized into four main groups — mouse events, keyboard events, form events and document/window events. There are many other events, we will learn about them in later chapters. The following section will give you a brief overview of the most useful events one by one along with the real life practice examples. Mouse EventsA mouse event is triggered when the user click some element, move the mouse pointer over an element, etc. Here're some most important mouse events and their event handler. The Click Event (onclick)The click event occurs when a user clicks on an element on a web page. Often, these are form elements and links. You can handle a click event with an The following example will show you an alert message when you click on the elements. ExampleTry this code »
The Contextmenu Event (oncontextmenu)The contextmenu event occurs when a user clicks the right mouse button on an element to open a context menu. You can handle a contextmenu event with an The following example will show an alert message when you right-click on the elements. ExampleTry this code »
The Mouseover Event (onmouseover)The mouseover event occurs when a user moves the mouse pointer over an element. You can handle the mouseover event with the ExampleTry this code »
The Mouseout Event (onmouseout)The mouseout event occurs when a user moves the mouse pointer outside of an element. You can handle the mouseout event with the ExampleTry this code »
Keyboard EventsA keyboard event is fired when the user press or release a key on the keyboard. Here're some most important keyboard events and their event handler. The Keydown Event (onkeydown)The keydown event occurs when the user presses down a key on the keyboard. You can handle the keydown event with the ExampleTry this code »
The Keyup Event (onkeyup)The keyup event occurs when the user releases a key on the keyboard. You can handle the keyup event with the ExampleTry this code »
The Keypress Event (onkeypress)The keypress event occurs when a user presses down a key on the keyboard that has a character value associated with it. For example, keys like Ctrl, Shift, Alt, Esc, Arrow keys, etc. will not generate a keypress event, but will generate a keydown and keyup event. You can handle the keypress event with the ExampleTry this code »
Form EventsA form event is fired when a form control receive or loses focus or when the user modify a form control value such as by typing text in a text input, select any option in a select box etc. Here're some most important form events and their event handler. The Focus Event (onfocus)The focus event occurs when the user gives focus to an element on a web page. You can handle the focus event with the ExampleTry this code »
Note: The value of The Blur Event (onblur)The blur event occurs when the user takes the focus away from a form element or a window. You can handle the blur event with the ExampleTry this code »
To take the focus away from a form element first click inside of it then press the tab key on the keyboard, give focus on something else, or click outside of it. The Change Event (onchange)The change event occurs when a user changes the value of a form element. You can handle the change event with the ExampleTry this code »
The Submit Event (onsubmit)The submit event only occurs when the user submits a form on a web page. You can handle the submit event with the ExampleTry this code »
Document/Window EventsEvents are also triggered in situations when the page has loaded or when user resize the browser window, etc. Here're some most important document/window events and their event handler. The Load Event (onload)The load event occurs when a web page has finished loading in the web browser. You can handle the load event with the ExampleTry this code »
The Unload Event (onunload)The unload event occurs when a user leaves the current web page. You can handle the unload event with the ExampleTry this code »
The Resize Event (onresize)The resize event occurs when a user resizes the browser window. The resize event also occurs in situations when the browser window is minimized or maximized. You can handle the resize event with the ExampleTry this code »
Advertisements
Advertisements
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |