Javascript/jQuery: Input with fixed prefix.

PHOTO EMBED

Mon Aug 29 2022 17:23:51 GMT+0000 (Coordinated Universal Time)

Saved by @marcopinero #html #css #javascript

//<input type="text" value="B01" id="MYINPUT">

$("#MYINPUT").select(function(e){
    var selSt=$(this)[0].selectionStart;
    var selNd=$(this)[0].selectionEnd;
    
    if (selSt<3) {
        $(this)[0].setSelectionRange(3, selNd);
    }
});

content_copyCOPY

Keep a fixed prefix (3 chars in this example) in an input[text] component.