Currently I'm working on a feature for a project and event.keyCode appears doesn't work for "on input" trigger. I'm using Google Chrome 31 and jQuery 1.10.2.
Here's what I tried inside my method:
input.on('input', function(event){
console.log("event.charCode: " + event.charCode);
console.log("event.keyCode: " + event.keyCode);
console.log("event.which: " + event.which);
console.log("window.event ? event.keyCode : event.which: " + window.event ? event.keyCode : event.which);
});
I get undefined
for all this methods. Am I doing something wrong or this is a jQuery / Javascript issue? Here you can find the fiddle.
I want that my input fires when user paste something inside it or change, by any way, the input content.
p.s: my method works as expected, the only thing that doesn't work is...this.
The event input does not have the keycode, but you can use the inputType property that way.
console.log(event.inputType);
event.inputType == "deleteContentBackward" // Backspace
event.inputType == "deleteContentForward" // Delete
event.inputType == "insertText" // When insert character
That is because you are using onkeypress instead of onkeydown!
Try doing it with onkeydown and you will be able to access e.keyCode.
so instead of:
<input onkeypress="getKeyValue()"/>
You should do:
<input onkeydown="getKeyValue()"/>
I hope this helps, good luck mate!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With