How to make only some text in a text-field read-only using Jquery

How to make only some text in a text-field read-only while allowing to be edited

var com_name_val_len = jQuery('#company_name').val().length;
jQuery('#company_name').on('keypress, keydown', function(event) {
    if ((event.which != 37 && (event.which != 39))
        && ((this.selectionStart < com_name_val_len)
        || ((this.selectionStart == com_name_val_len) && (event.which == 8)))) {
        return false;
    }
});

 

Leave a Reply

Your email address will not be published. Required fields are marked *