Author Topic: Javascript and the onkeypress event  (Read 405 times)

Offline Sraet

  • Level 6
  • *
  • Posts: 24
  • Reputation: +0/-0
    • View Profile
Javascript and the onkeypress event
« on: March 06, 2009, 06:08:33 PM »
Why does <body id="body" onkeypress="return SomeFunc(event)"> work but document.getElementById("body").onkeypress=SomeFunc; not work??? Every google search comes up with onkeypress as part of the XHTML, and I would prefer to avoid having to embed it in there like that.

Offline Sraet

  • Level 6
  • *
  • Posts: 24
  • Reputation: +0/-0
    • View Profile
Re: Javascript and the onkeypress event
« Reply #1 on: March 06, 2009, 08:24:39 PM »
nevermind, it turns out if you just want to snag all key input you attach it to the document's events, not the body's.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal