1 <html> 2 <head> 3 <script type="text/javascript"> 4 window.onload = function() { 5 document.getElementById('test').addEventListener('keypress', function(e) { 6 out = document.getElementById('out'); 7 out.innerHTML = 'keyCode: ' + e.keyCode + ' (should be 13)'; 8 if (e.keyCode == 13) 9 out.style.background = '#6f6'; 10 else 11 out.style.background = '#f66'; 12 }, false); 13 document.getElementById('test').focus() 14 }; 15 </script> 16 </head> 17 <body> 18 <p>Press the numpad Enter key while the input box below is focused:</p> 19 <p><input type="text" id="test" /></p> 20 <p id="out"></p> 21 </body> 22 </html> 23