I am trying the following code for triggering a js method when space-bar is pressed within an input box.
$(\'#j1
if you're getting a 0 no matter which key you press, try using charCode instead of keyCode
This happens because you are calling the KeyboardEvent object which uses which and charCode as opposed to the Event object which uses keyCode for returning keyboard Unicode values. For more information, refer to MDN web docs for more information regarding the KeyboardEvent:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent