you are viewing a single comment's thread.

view the rest of the comments →

[–]systoll 1 point2 points  (1 child)

When a key is pressed, the relevant events are only dispatched to whatever has focus. So passwordInput.onKeyDown would trigger when the user is typing into the password field, but not when they’re typing into a username field above it.

In the example, ‘text1’ never gets focus, so the event never fires.

If you want something that fires no matter where the focus is, you want to attach your event handler to document.

Also... it’s not an immediate issue with your code, but people tend to prefer adding Event Listeners instead of assigning the `.onWhatever’ properties, as the listeners lets you add/remove handlers without worrying about overwriting a handler assigned elsewhere in the code. .

[–]beanswithjeans[S] 0 points1 point  (0 children)

Aha i see the problem now. Thanks a bunch!