Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var otherCase = function () {
document.getElementById('field').value = document.getElementById('field').value.toUpperCase();
}
window.onload = otherCase;
function DisplayKey (e) {
e = e? e : window.event;
//which key has been pressed?
var keycode = e.keyCode? e.keyCode : e.which? e.which : null;
if(keycode)
document.getElementById('keys').firstChild.nodeValue += String.fromCharCode(keycode);
}
document.onkeypress=DisplayKey;
</script>
</head>
<body>
<form action="javascript:void();" onsubmit="return false;">
<table align="center">
<tr><td><b>Input Field:</b></td>
<td><input name="fld" type="text" id="field" onblur="otherCase();"></td>
</tr>
</table>
</form>
<h1>Display pressed keys:</h1>
<div id="keys">
</div>
</body>
</html>
Edit: You might want to add the event onkeypress to the (or another) input field instead of to the document, example:
Code:
<input name="fld" type="text" id="field" onblur="otherCase();" onkeypress="DisplayKey(event);">
Also, although the code tested fine, I've often heard that onkeydown is preferred for this sort of thing.
Bookmarks