Home arrow JavaScript arrow Page 8 - Understanding The JavaScript Event Model (part 1)

Linking Up - JavaScript

This may be news to you, but JavaScript comes with a powerfuland flexible event model, one which provides developers with astandardized way of trapping and handling client-side events likekeystrokes and mouse clicks. This two-part article takes an in-depthlook at how this event model works, demonstrating some practical (andnot-so-practical) uses of the most common event handlers.

  1. Understanding The JavaScript Event Model (part 1)
  2. Popeye() And Olive()
  3. Handling Things
  4. Red Alert
  5. Mouse Hunt
  6. Forty Two
  7. Flavour Of The Month
  8. Linking Up
  9. Game Over
By: Team Melonfire, (c) Melonfire
Rating: starstarstarstarstar / 36
June 25, 2002

print this article


Finally, the onSelect and onChange handlers come in handy when dealing with selection lists and editable text fields. Consider the following example, which demonstrates them both:

<form action="submit.php" method="post">
Enter the name of your favourite superhero:
<input type="text" name="superhero" onSelect="alert('You just selected
something!')" onChange="alert('You just changed something!')"> </form>
In this case, when the contents of the text field are selected, the onSelect handler is triggered - and when the contents are changed, the onChange handler is triggered and an appropriate message displayed.

The onChange handler is frequently used with drop-down selection lists, as in the following example:
<script language="JavaScript">
function goto() 
document.location.href =
<form action="submit.php" method="post">
Select from the list below:
<select name="url" size="1" onChange="goto()">
<option value="http://www.melonfire.com/">Melonfire</option>
<option value="http://www.yahoo.com/">Yahoo!</option>
<option value="http://www.cnn.com/">CNN</option>
In this case, when the user makes a selection from the list, the onChange handler is triggered and the goto() function invoked. This function looks up the list to find the index of the currently-selected item, and uses the corresponding value to redirect the browser to the named URL.

>>> More JavaScript Articles          >>> More By Team Melonfire, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Javascript for Beginners: An Introduction
- Introduction to JavaScript
- Adding Elements to a Tree with TreeView jQue...
- Using the Persist Argument in a TreeView jQu...
- Using Unique and Toggle in a TreeView jQuery...
- Using Event Delegation for Mouseover Events ...
- Using the Animate Option in a Treeview jQuer...
- Using HTML Lists with Event Delegation in Ja...
- Opened and Closed Branches on a TreeView jQu...
- Mouseover Events and Event Delegation in Jav...
- Creating a TreeView JQuery Hierarchical Navi...
- Event Delegation in JavaScript
- A Look at the New YUI Carousel Control
- Working with Draggable Elements and Transpar...
- Displaying Pinned Handles with Resizable Con...

Developer Shed Affiliates


Dev Shed Tutorial Topics: