I have the text box which only accepts number and dot so that i can enter decimal number.Also i need to get last entered value from that text. I used the following piece of code using onkeypress event using java script
function only_numeric(e,val)
{
var keynum;
var keychar;
var numcheck;
if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // netscape/Firefox/opera
{
keynum = e.which;
}
//condition for backspace(8) Key
if(keynum != 8)
{
keychar = String.fromCharCode(keynum);
//numcheck = /\d/;
numcheck = /[.0-9]/;
if(numcheck.test(keychar))
{
alert(keychar);
}
return numcheck.test(keychar);
}
else
{
return true;
}
}
This one alert empty when i enter first number then again if i entered second it alert first number, finally i missed last value .I am calling only_numeric function on ‘onkeypress’ kindly help me on this.
I suggest you to use onkeyup. Check below code
Or
check this code and implement it in your code.
});