While entering value in the textbox, when I enter value in between the entered value cursor moves automatically to the end of the value.
<!DOCTYPE html>
<html>
<body>
<script>
function truncate(x) {
if(x.value.length > 0)
{
x.value = x.value.replace(/^\s+/, '');
}
}
</script>
<input id="otherText" onkeyup="javascript:truncate(this);" maxlength="12" type="text"/>
</body>
</html>