Anyone know how to get onkeypress to work with keycode? I need to figure out what the keycode is before the character shows up in a textbox. Here is the code I have so far (see below). I can get the value to show with onkeydown or up, but it shows the typed value in the textbox even if it does not fit my criteria.
[code=javascript]
//Call it with onkeypress = return stripper(event)
function stripper(e)
{
var bRes = false;
if((e.keyCode >= 48)&&(e.keyCode <=57))
{
alert(e.keyCode );
bRes=true;
}
else
{
alert("Numeric Values Only");
}
return bRes;
}
[/code]
Basically what this is supposed to do is not show the typed character if it is anything but a number. With onkeypress Mozilla returns a 0 for the keyCode... No issues with IE.
[code=javascript]
//Call it with onkeypress = return stripper(event)
function stripper(e)
{
var bRes = false;
if((e.keyCode >= 48)&&(e.keyCode <=57))
{
alert(e.keyCode );
bRes=true;
}
else
{
alert("Numeric Values Only");
}
return bRes;
}
[/code]
Basically what this is supposed to do is not show the typed character if it is anything but a number. With onkeypress Mozilla returns a 0 for the keyCode... No issues with IE.
Comment