Created
April 28, 2009 19:37
-
-
Save johnantoni/103343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function killKeys() { | |
//stop backspace / escape / enter key | |
if (typeof window.event != 'undefined') // IE | |
document.onkeydown = function() // IE | |
{ | |
var t=event.srcElement.type; | |
var kc=event.keyCode; | |
//alert('Type: ' + t); | |
return ((kc != 8 && kc != 13 && kc != 27) || (t == 'text' && kc != 13 && kc != 27) || | |
(t == 'textarea' && kc != 27) || (t == 'button' && kc == 13) || (t == 'submit' && kc == 13) || | |
(t == 'password' && kc != 27 && kc !=13) || (t == '' && kc == 13)) | |
// Type = '' is what I get from the A HREF elements that need to remain functional in my form | |
} | |
else | |
document.onkeypress = function(e) // FireFox/Others | |
{ | |
var t=e.target.type; | |
var kc=e.keyCode; | |
if ((kc != 8 && kc != 13 && kc != 27) || (t == 'text' && kc != 13 && kc != 27) || | |
(t == 'textarea' && kc != 27) || (t == 'button' && kc == 13) || (t == 'submit' && kc == 13) || | |
(t == 'password' && kc != 27 && kc !=13) || (t == '' && kc == 13)) | |
// Type = '' is what I get from the A HREF elements that need to remain functional in my form | |
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