Skip to content

Instantly share code, notes, and snippets.

@dublado
Created December 16, 2011 22:14
Show Gist options
  • Select an option

  • Save dublado/1488257 to your computer and use it in GitHub Desktop.

Select an option

Save dublado/1488257 to your computer and use it in GitHub Desktop.
block enter and backspace
if (typeof window.event != 'undefined') // IE
document.onkeydown = function() // IE
{
var t=event.srcElement.type;
var kc=event.keyCode;
return ((kc != 8 && kc != 13) || ( t == 'text' && kc != 13 ) ||
(t == 'textarea') || ( t == 'submit' && kc == 13))
}
else
document.onkeypress = function(e) // FireFox/Others
{
var t=e.target.type;
var kc=e.keyCode;
if ((kc != 8 && kc != 13) || ( t == 'text' && kc != 13 ) ||
(t == 'textarea') || ( t == 'submit' && kc == 13))
return true
else {
alert('Sorry Backspace/Enter is not allowed here'); // Demo code
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment