<html> | |
<head> | |
<script type="text/javascript"> | |
window.onload = function() { | |
document.getElementById('test').addEventListener('keypress', function(e) { | |
out = document.getElementById('out'); | |
out.innerHTML = 'keyCode: ' + e.keyCode + ' (should be 13)'; | |
if (e.keyCode == 13) | |
out.style.background = '#6f6'; | |
else | |
out.style.background = '#f66'; | |
}, false); | |
document.getElementById('test').focus() | |
}; | |
</script> | |
</head> | |
<body> | |
<p>Press the numpad Enter key while the input box below is focused:</p> | |
<p><input type="text" id="test" /></p> | |
<p id="out"></p> | |
</body> | |
</html> |