Q:

JS: Detect key pressed in text input from onkeydown() inline function

I have the following
<input name='blah[]' onkeydown="itemKeyDown(this)">

Is it possible to detect what key was pressed in the itemKeyDown() function?
I tried the usual approach with:
e.keyCode || e.which

but it returns undefined.
To note:
I could do it the jQuery way but i needed to specifically attach the function call in the HTML code (inside the  tags) because im dynamically generating a lot of copies of this text field, and this way all fields generated will inherit the function call. I dont want to have to bind a listener to a text field everything one is generated.

A:

Like that?

function itemKeyDown(e) {
    console.log(e.keyCode || e.which);
}
<input name='blah[]' onkeydown="itemKeyDown(event)">

A:

<input name='blah[]' onkeydown="itemKeyDown(this)">

this keyword doesn't carry any information about the event onkeydown it represent the  DOM element (input)
to get the event data you should pass event keyword like: 

<input name='blah[]' onkeydown="itemKeyDown(event)">

<script>
function itemKeyDown(e)
{
  console.log(e.keyCode)
}

</script>

