
// Trap Esc(27), Backspace(8) and Enter(13) - 
// Except bksp on text/textareas/password, enter on textarea/submit/link

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
}
}

