The keydown event fires right before the keypress event when a user is typing.
Scripting keydown events through Javascript and the DOM:
Javascript CODE EXAMPLE
<script type="text/javascript">
function addEventsToHTML(){
var field1 = document.getElementById('field1');
field1.onkeydown = reflect;
function reflect(){
document.getElementById('status').innerHTML = this.value;
}
}
window.onload = addEventsToHTML;
</script>
<input id="field1">
<span id="status"></span>
Establishing keydown events direct on the html elements:
Javascript CODE EXAMPLE
<script type="text/javascript">
function reflect(target){
document.getElementById('status').innerHTML = target.value;
}
</script>
<input onkeydown="reflect(this);">
<span id="status"></span>