SolutionCottage.com
Posted  24 Feb 2009 - 11:53:45

Category: JavaScript


get the char from e.keyCode

Issue:
You have a textarea like this one:

<textarea [...] onkeypress="preventSomeInput(event)">

In the preventSomeInput function you mighy want to know what key was pressed. We send the event along to the function. This is how you read out and convert the code to a char:

Solution:

function preventSomeInput(e)
{
var pressedKey = String.fromCharCode(e.keyCode);
alert("Pressed key: " + pressedKey);
}



Marked as helpful by 8 users




0 comments:








© SolutionCottage 2008-2011 9/26/2017 10:08:06 AM