Trap Enter (or any other key).

by Svelmoe 12. August 2007 17:28

This is in the same line of thinking as the Hook F5 mention.

Sometimes it is usefull to "trap" a key - especially enter - and to do something other then the normal form submit or what ever.

function trapEnter(e)
{
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true
  if (keycode == 13)
  { 

    //If enter should do nothing
    /*
    e.returnValue = false;
    e.cancel = true;
    return false;
    */
    //Otherwise - do stuff
  }
  return true;
}

 

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



About Svelmoe

My real name is Allan Svelmøe Hansen.

I live in Denmark, where I work as a developer for hedal:kruse:brohus using SQL Server and the .NET framework since 2004. Svelmoe.dk is a place for my every day thoughts and reactions and the occasional technical blog entry.

I also blog about SQL and MS SQL Server at www.execsql.com so in case you are looking for more about that, please visit that website.



View Allan Svelmøe Hansen's profile on LinkedIn     

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 Svelmoe.dk