View Single Post
  #2 (permalink)  
Old January 8th, 2007, 09:37 AM
dparsons dparsons is offline
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I use a similiar function, however, it prevents a user from pressing the enter button and having it submit a form.

function keyPress(e)
{
    var pressedKey = document.all? window.event.keyCode:e.which;
    return pressedKey != 13;
}
document.onkeypress = keyPressed;
if (document.layers) document.captureEvents(Event.KEYPRESS);

What this does is if the numerical representation of the pressed key is 13 (Key code for the enter button) it is disregarded and thus the enter button press do not do anything on the page this function is implemented on.

To do what you want, you would alter the above function so that if the keycode is 13 you would call .focus on a form element.

hth.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature