How to disable keypress or restrict to write in a html input element in jQuery?
author
,
Aspirant Programmer

How to disable writing in html input element using jQuery?

  • Total 1 Answer
  • 136
Can You answer this question?
author
,
Aspirant Programmer

If we want to disable writing in a field using jQuery we can do this by writing below code. Actually sometime we don't want anybody to edit information written in a html input element but want that field populated with some default text then use the below line code to do this:

$(document).ready(function(){
        
        //Disable address edit on checkout page
        $(".ty-billing-address input").on("keydown keypress keyup", false);

        // these below line are not required, you can use this if html elements are loaded with ajax then it will be useful.
        $(document).ajaxComplete(function(){
            $(".ty-billing-address input").on("keydown keypress keyup", false);            
        });
    });

".ty-billing-address input" you need to use your input element instead of this one.