You are here: irt.org | FAQ | JavaScript | Event | Q985 [ previous next ]
Try:
<html> <head> <script language="JavaScript1.2"><!-- function netscapeKeyPress(e) { if (e.which == 13) alert('Enter pressed'); } function microsoftKeyPress() { if (window.event.keyCode == 13) alert('Enter pressed'); } if (navigator.appName == 'Netscape') { window.captureEvents(Event.KEYPRESS); window.onKeyPress = netscapeKeyPress; } //--></script> </head> <body onKeyPress="microsoftKeyPress()"> <form name="test"> <textarea></textarea> <input type="text"> </form> </body> </html>
Only the textarea appears to work on Netscape Navigator 4.5 on GNU/Linux.
The onBlur event handler can be used to detect when a field loses focus:
<form> <input type="text" onBlur="alert('Enter *might* have been pressed')"> </form>