Disable backspace key using Jquery

Disable backspace key in HTML form using Jquery in simple steps.

While user enters data into application if user accidentally press backspace button then it will redirect to previous page and all entered data would be lost. to eliminate this event we can disable the backspace key using Jquery.

Following is the JQuery script tag you can add to the web page

$(document).keydown(function (e) {
    var nodeName = e.target.nodeName.toLowerCase();

    if (e.which === 8) {
        if ((nodeName === 'input' && e.target.type === 'text') ||
            nodeName === 'textarea') {
            // do nothing
        } else {
            e.preventDefault();
        }
    }
});

The above code can be used seamlessly with any web technology you are using. Hope this will help you in your web application.

Happy coding:)

Comments

Post a Comment

Popular posts from this blog

Restore the lost focus of Auto post back controls in asp.net update Panel control

Clone a generic list in C# using extension method

Step by step migration of ASP.NET Core 2.2 to 3.1

Add Comma automatically while entering amounts in textbox using Javascript

Remove Owin from MVC 5 Application and use asp.net custom forms authentication

Source Code Beautifier And Format Source Code For Blogger and Websites

Email validation using regular expression in jQuery

Send bulk Email in asp.net using excel file