JavaScript
  Home arrow JavaScript arrow Page 8 - Understanding The JavaScript Event Mod...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Understanding The JavaScript Event Model (part 2)
By: Team Melonfire, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 29
    2002-07-10

    Table of Contents:
  • Understanding The JavaScript Event Model (part 2)
  • Back To Basics
  • How's The Weather Up There?
  • X Marks The Spot
  • Enter The Stalker
  • Of Keys And Clicks
  • A Few Modifications
  • Tonight's Menu
  • Reducing The Crime Rate
  • Endgame

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Understanding The JavaScript Event Model (part 2) - Tonight's Menu
    (Page 8 of 10 )

    Next, let's look at a couple of examples that demonstrate the possible applications of this capability. This next example sets up a small menu containing multiple links, each link associated with a number. The user can select a specific link by pressing the appropriate number key on the keyboard.

    Here's the code for Netscape Navigator:
    <html>
    <head>
    <script language="JavaScript">
    function menuSelect(e) 
    {
    // select 1
    if(e.type == 'keydown' && e.which == 49)
    {
    document.location.href="link1.htm"
    } 
    // select 2
    else if(e.type == 'keydown' && e.which == 50)
    {
    document.location.href="link2.htm"
    }
    // select 3
    else if(e.type == 'keydown' && e.which == 51)
    {
    document.location.href="link3.htm"
    }
    // select 4
    else if(e.type == 'keydown' && e.which == 52)
    {
    document.location.href="link4.htm"
    }
    }
    document.onkeydown = menuSelect;
    </script>
    </head>
    <body>
    </body>
    </html>
    And here's the Internet Explorer equivalent:
    <html>
    <head>
    <script language="JavaScript">
    function menuSelect() 
    {
    // select 1
    if(event.type == 'keydown' && event.keyCode == 49)
    {
    document.location.href="link1.htm";
    } 
    // select 2
    else if(event.type == 'keydown' && event.keyCode == 50)
    {
    document.location.href="link2.htm";
    }
    // select 3
    else if(event.type == 'keydown' && event.keyCode == 51)
    {
    document.location.href="link3.htm";
    }
    // select 4
    else if(event.type == 'keydown' && event.keyCode == 52)
    {
    document.location.href="link4.htm";
    }
    }
    document.onkeydown = menuSelect;
    </script>
    </head>
    <body>
    </body>
    </html>
    A quick note on something new here: in both cases, the "type" property has been used to identify the type of event generated. This makes it possible to take action selectively, on the basis of the specific type of event generated.

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


     

       

    JAVASCRIPT ARTICLES

    - Getting Attention with Interactive Effects
    - Interacting with Tooltips and Previews
    - Just-in-Time Information and Ajax
    - Interactive Effects
    - Using Cookies With JavaScript
    - Understanding the JavaScript RegExp Object
    - Controlling Browser Properties with JavaScri...
    - Using Timers in JavaScript
    - Form Validation with JavaScript
    - JavaScript Exception Handling
    - Stringing Things Along
    - Understanding The JavaScript Event Model (pa...
    - Understanding The JavaScript Event Model (pa...
    - An Object Lesson In JavaScript

    Iron Speed
     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway