Bart Van der Donck wrote:
In IE, the problem is trivial, because window.event.keyCode can be set,
but in Firefox the event.which property appears to be read only.
I don't think this is correct. AFAIK, keyCode should be read-only
too.
(AFAIK==as far as I know?)
The following code works in IE to replace an "enter" keystroke with a
"tab" keystroke in the first text box:
<html>
<head><title></title>
<script type="text/javascript">
function replace(e) {
if (e.keyCode==13) e.keyCode=9
}
</script>
</head>
<body>
<form>
<input onkeydown="replace(event)" /><br />
<input />
</form>
</body>
</html>
If you replace the "keyCode" property with the "which" property for
Firefox, the code does not work in Firefox.
Bart Van der Donck wrote:
Your problem is more fundamental. You want to make javascript think the
user pressed a key, while he actually didn't press it. It's spoofing by
definition - browsers are right to complain about this kind of
trickery. My gut feeling is that you should give up your plan and
rethink your coding strategy.
And honestly I can't think of any good reason why you would want to
fake a keystroke, besides theoretical or hacking motives.
The purpose is for a data entry application, such as when using the
numeric keypad to enter data. Typically, the "enter" key will work
like a "tab" key until the last field on the form. Using
String.fromCharCode(9) to append to the fields's value only appends a
"tab" character just like in a word processing application, but does
not cause the cursor to move to the next field. Any ideas on how to
make "enter" work like "tab" in Firefox?