View Full Version : Simulating Key Strokes

05-25-2005, 11:58 AM
Hiya Folks,

I trying to replace the key behaviour when a user presses the ENTER key in a input field. Put simply when a user presses Enter I want to the browser to act as if they'd pressed TAB.

The code I have so far is as follows :

function MyDelete(MyName){

var pKey = window.event.keyCode;

if(pKey==8||pKey==46) //disable the backspace and delete keys
window.event.cancelBubble = true;
window.event.returnValue = false;
return false;
else if(pKey == 13) //detect the ENTER key and replace with TAB
alert("Enter Pressed")

window.event.keycode = 9



This function is called from the input field as follows :


The function is detecting that the Enter key has been pressed but it isn't changing the behaviour, which in this case is trying to Subit the form. I'm trying to replace this so the user can enter values into the field press Enter and move onto the next field. Using nothing other than the Number pad on the keyboard.

This is on an intranet and the only browser is IE

Any offers?

05-25-2005, 04:45 PM
try adding \t not keyCode 9

05-25-2005, 04:49 PM
at the risk of ridicule, add it to what??

05-25-2005, 04:58 PM
well, looking at your code i'm not quite following how your returning the 'tab' to the textarea (or RichTextDoc).

However, if you are intercepting the 'enter' and replacing it with a 'tab' then


is the escape char for tabs.