PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
Javascript Disable the Back Key shortcut in Forms
A lot of the web based applications I build incorporate html forms to allow the user to enter data. I make use of the page expires features to stop the users going back through the browser history and replaying stale transactions. I found that occasionally some users would have problems where they would hit the Backspace key while the focus was not inside of a form field and this would trigger the keyboard short cut of History Back and the user would get an ugly page expired message and then loose their current place and data.

To solve this problem I added some javascript to the page which disabled the backspace key on pages with Forms where the user did not have focus in an editable field (we still want backspace to work in the text fields):

function fFormKeyDownProcess(){ 
        var elm=event.srcElement; 
        // only allow backspace if the event came from 
        // a text or textarea element. 
        if(elm.type!="text" && elm.type!="textarea" && event.keyCode==8){ 
                event.returnValue=false; 
                return false; 
        } 
}
To make use of the code just add a call to the function in your keydown attribute/event on the form element of your page.
 

Top of Page

Legal Notice

Ken Howe 2011