Search code examples
javascriptfunctioneventsonkeypress

Javascript: Pass event AND element reference


I want an input field which calls a javascript function, if a key is pressed. But I'm not able to pass the event as well as an element reference. I can either pass the event:

<input type="text" name="chmod" value="644" onkeypress="chmod(e)">

or pass the element reference:

<input type="text" name="chmod" value="644" onkeypress="chmod(this)">

If I try to pass both there occurs an error:

<input type="text" name="chmod" value="644" onkeypress="chmod(e, this)">

Uncaught ReferenceError: e is not defined

Is there any way to pass both, the event and a reference to the element?

Cheers, Marco


Solution

  • <input type="text" name="chmod" value="644" onkeypress="chmod(event, this)">