I would like to hook a character typed in an input text field and type '1' in the field in case 'a' was pressed.
Here is the code:
<html>
<body>
<script type="text/javascript">
function translate_code(charCode) {
switch (charCode) {
case 65: //
return '1' ;
case 97:
return '9';
}
}
function noEnglish(event) {
if (event.charCode) {
var charCode = event.charCode;
} else {
var charCode = event.keyCode;
}
if (65 <= charCode && charCode <= 90) {
document.getelementbyid("my_name").value += translate_code(charCode) ;
event.returnValue = false ;
}
}
</script>
<form>
<input type="text" name="my_name" id="my_name" onkeydown="noEnglish(event)" />
</form>
</body>
</html>