Background
When using the default Android browser (internet) on the Samsung Note, and maybe other Andriod device, when editing input field using the type "numeric" , the keyboard, which is a number pad, does not have a decimal button on it!
<input id="x" type="number" value="" />
I noticed the Bank of America Andriod app does not have a decimal on the number pad. This is how they handle it.
- click on field
- type first number "1" and field display 0.01
- type second number "2" and field display 0.12
- type third number "3" and field display 1.23
- type forth number "4" and field display 12.34
I would like to mimic this functionality on my web site that will be used for from mobile devices.
This demo from mplungjan is very close. I want to show two places decimal all the time and this solution shows does not until the forth character is press:
$("#txtamt").keyup(function(obj, evt) {
var event = (window.event) ? window.event : evt;
//ignore arrow keys so that user can move curser
switch(event.keyCode)
{
case 37:
case 38:
case 39:
case 40:
return;
default:
break;
}
var str = document.getElementById("txtamt");
str.value = str.value.replace(".", "");
if (str.value.length == 3) {
var val = parseFloat(str.value);
var val1 = (val / 10).toFixed(1);
str.value = val1;
}
else if (str.value.length > 3) {
var val = parseFloat(str.value);
var val1 = (val / 100).toFixed(2);
str.value = val1;
}
});
One obvious solution is just to change the input type and have the standard full keyboard display.