Show Each Char As It Is Typed – II

[Total: 0    Average: 0/5]

This shows how to use either NS or IE to trap the character as it is type by the user.

Body Code:

<script type=text/javascript>
if (navigator.appName == 'Netscape'){ 
document.captureEvents(Event.KEYPRESS); 
} 
// these next 2 could be used, but will not catch the delete key in IE 5.5
//document.onkeypress = KeyPress1; 
//document.onkeydown = KeyPress2;

// IE 4.0 used to use keypress for delete
// IE 5.5 uses onkyup to catch the delete key.
document.onkeyup = KeyPress3;
function KeyPress1(e){ 
if (navigator.appName == 'Netscape'){ 
document.exf1.key.value=e.which + " = ("+String.fromCharCode(e.which)+")"; 
} 
if (navigator.appName == 'Microsoft Internet Explorer'){ 
document.exf1.key.value=window.event.keyCode + " = ("+String.fromCharCode(window.event.keyCode)+")[1]";
}
} 
function KeyPress2(e){ 
if (navigator.appName == 'Netscape'){ 
document.exf1.key.value=e.which + " = ("+String.fromCharCode(e.which)+")"; 
} 
if (navigator.appName == 'Microsoft Internet Explorer'){ 
document.exf1.key.value=window.event.keyCode + " = ("+String.fromCharCode(window.event.keyCode)+")[2]";
}
} 
function KeyPress3(e){ 
if (navigator.appName == 'Netscape'){ 
document.exf1.key.value=e.which + " = ("+String.fromCharCode(e.which)+")"; 
} 
if (navigator.appName == 'Microsoft Internet Explorer'){ 
document.exf1.key.value=window.event.keyCode + " = ("+String.fromCharCode(window.event.keyCode)+"[3])";
}
} 

</script>
<form name=exf1>
<input type=text name=key value="?">
</form>

Times Viewed: 3

Leave a Reply

Your email address will not be published. Required fields are marked *