I have an input field
<input style="width: 570px;" id="storagememory" min="0" max="9999" type="text">
At first it may seem strange, with a minimum and a max. But you see, I have the following Javascript that changes it this way:
document.getElementById('storagememory').addEventListener('blur', function()
{document.getElementById('storagememory').setAttribute('type','text');
document.getElementById('storagememory').value = document.getElementById('storagememory').value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
});
document.getElementById('storagememory').addEventListener('focus', function()
{document.getElementById('storagememory').value = document.getElementById('storagememory').value.toString().replace(/\D/g,'');
document.getElementById('storagememory').setAttribute('type','number');
});
Therefore, when an input is focused, it becomes an input / number. Thus, the minimum and maximum values ββare respected, and I get the UI up / down (both in the form of buttons, and when I press the up / down keys). When the focus is lost, it becomes input / text, so I can format it accordingly with a comma divided by thousands, millions, etc.
The problem is that the input is focused, I lose the ability (Firefox 30.0) to enter numbers into it.
My question is: how to restore the ability to enter numbers in this field without losing the ability to display non-numeric data when they are not focused?
0 9999. , 999. ... a parseInt() "", , .
, .