function fn() {
var element = document.getElementById("NumberInput");
element.value = "";
element.onkeydown = function (e) {
if (element.value.length == 0) {
element.value = "M";
}
};
element.onkeyup = function (e) {
if (e.keyCode == 8) {
var Number = element.value;
var caretPos = element.selectionStart;
if (caretPos == element.value.length) {
Number = Number.replace('M', '');
Number = Number.substring(0, Number.length - 1);
element.value = Number + 'M';
}
}
else {
var Number = element.value;
Number = Number.replace('M', '');
element.value = Number + 'M';
}
};
}
call this on body onload. if you familiar with jquery you can do this less no of lines. this is pure javascript solution for your problem. hope this helps.