topical media & game development

talk show tell print

#javascript-code-07-keybaord.js / js



  // Watch for input in the entry field
  id("q").onkeypress = function(e){
      // Get all of the users in the result set
      var li = id("results").getElementsByTagName("li");
          
      // If the [TAB] or [Enter] keys are pressed
      if ( e.keyCode == 9 || e.keyCode == 13 ) {
          // Add the user to the text entry field
      
      // If the up key is presssed
      } else if ( e.keyCode == 38 )
          // Select the previous user, or the last user (if we're at the beginning)
          return updatePos( curPos.previousSibling || li[ li.length - 1 ] );
          
      // If the down key is pressed
      else if ( e.keyCode == 40 )
          // Select the next user, or the first user (if we're at the end)
          return updatePos( curPos.nextSibling || li[0] );
  };
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.