A variant to hit the only significant digits following by Enter
Use only the keypad with .1 Enter for 0.100 .75 Enter for 0.750 and 50 Enter for 50.000 ... etc.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
<style type="text/css">
input {width:400px;}
</style>
</head>
<body>
<label for=lsr>Quantity field <input id="txt" type="text" value="" onkeyup="entry(event)"></label>
<script type="text/javascript">
/*
0.100 0.150 0.200 0.250 0.500 0.750 1.000 1.250 1.500 1.750 2.000
3.000 4.000 5.000 6.000 7.000 8.000 9.000 10.000 15.000 20.000 30.000
50.000 100.000 500.000 1000.000
*/
document.getElementById('txt').onkeyup=function(e){
var e=e?e:window.event,k=e.keyCode; //alert(k)
// Authorized keys : Enter, space, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and .
keys={13:1,32:1,96:1,97:1,98:1,99:1,100:1,101:1,102:103,104:1,105:106,110:1}
var str=document.getElementById('txt'),previousEnt,lastEnt;
// Remove non authorized entries
if (!keys[k]) {str.value=str.value.replace(/[^\d\.\s]+/g,'');return;}
// Enter : Format the last Entry
if (k==13){(" "+str.value).replace(/(.*)\s+([^\s]+)$/,function(a,b,c){previousEnt=b.substr(1);lastEnt=c});
str.value=previousEnt+' '+(+lastEnt).toFixed(3)+' ';}
}
document.getElementById('txt').focus();
</script>
</body>
</html>
NB : Add a 8:1, at the beginning of the authorized keys to allows backspace for corrections
How to avoid typing(SOLVED)
Thank you for your help.
My app is working very well; as a matter of fact I am using the <Datalist> and it works just great.
Thanks again.