How do I disable backspace keystroke if anything other than 2 specific input fields are focused on using jquery?
here is my current code (NOW INCLUDING 2 TEXTBOXES):
@Nick Craver, disgraceful answer for a couple of reasons. Answer the question or at least patronize thoughtfully.
Here is a prototype based solution I ended up using for my forms because users complained that backspace would take them away from the form (which is such an obviously counterintuitive thing to do, one wonders why all browsers use the backspace key as back button).
// event handlers must be attached after the DOM is completely loaded
Event.observe(window, 'load', function() {
// keypress won't fire for backspace so we observe 'keydown'
Event.observe(window, 'keydown', function(event){
// 8 == backspace
if( event.keyCode == 8) {
// with no field focused, the target will be HTMLBodyElement
if( event.target == document.body) {
// stop this event from propagating further which prevents
// the browser from doing the 'back' action
event.stop();
}
}
});
});