Enhanced Only Digits

[Total: 0    Average: 0/5]

This will only allow digits to be entered into the text box.

Body Code:

<form>
<INPUT name=txtQty TYPE=text size=6 onkeypress="return onlyDigits(event,'noDec')">
<INPUT name=txtPrice TYPE=text size=6 onkeypress="return onlyDigits(event,'decOK')">
</form>
<script>
var isIE = document.all?true:false;
var isNS = document.layers?true:false;

function onlyDigits(e,decReq) {
var key = (isIE) ? window.event.keyCode : e.which;
var obj = (isIE) ? event.srcElement : e.target;
var isNum = (key > 47 && key < 58) ? true:false;
var dotOK = (key==46 && decReq=='decOK' && (obj.value.indexOf(".")<0 || obj.value.length==0)) ? true:false;
if(key < 32)
   return true;
return (isNum || dotOK);
}


</script> 

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *