I know that when working with JavaScript or jQuery. I can add an event listener on an object to call a function when a key is pressed.
However, if the function is launched from HTML, as in the following example:
function callMyFunction (importantothervalue) {
//How can I get the keycode?
}
<textarea onkeyup="callMyFunction(1);"></textarea>
<textarea onkeyup="callMyFunction(2);"></textarea>
<textarea onkeyup="callMyFunction(3);"></textarea>
Is there any way to retrieve the key code from this context? Or do I always need to make an event handler if I want to get the key code?
Is there any way for me to include importantothervalue in the resulting function call without encoding the information in the id or class attribute and extracting it from there?
<textarea onkeyup="callMyFunction(event, 3);"></textarea>
and in method you can access key code by event.keyCode – Bodnar