Archive for the ‘Javascript’ Category

Here is a code which disables backspace by javascript / jQuery. It allows to use backspace in non readable form elements.
Tested in IE8, IE9, Firefox 5, Chrome 11, Opera 11.
It will also work for elements which don’t exist and are loaded lately by AJAX.

1
2
3
4
5
6
7
8
9
10
11
12
13
jQuery(document).keydown(function(e){      
        if (e.keyCode === 8){
            if( e.target.tagName=="INPUT" || e.target.tagName=="TEXTAREA"){
                var isReadOnly = jQuery(e.target).attr("readonly");
                if(isReadOnly=="readonly"){
                    return false;
                }else{
                    return true;
                }
            }
            return false;
        }
      })
Share