...

View Full Version : Hacking Return Key to Tab, then Space on Button



insidion
05-06-2008, 06:14 PM
This thing is frustrating me off to no end. I'm using javascript to hack the actions of a page so that when enter is pressed it carries on to the next form and behaves like the tab key was pressed (essentially just grabbing the character code and swapping it).

The issue comes in, when I try to replace it with space, so that it presses the button it's on rather than select the default, it just refreshes the page.

Am I using the wrong ascii code or is there something else that i'm missing?



document.onkeydown = tabOnEnter;

function tabOnEnter(evt)
{
evt = (evt)? evt : ((event)? event : null);
if (evt)
{
if ((evt.keyCode == 13) && (document.activeElement.type != 'submit'))
{
evt.keyCode = 9;
return evt.keyCode;
}
else
{
evt.keyCode = 32;
return evt.keyCode;
}
}
}

mrhoo
05-06-2008, 07:24 PM
document.activeElement is IE only, and event.keyCode is read only.
The keypress and keyup events will also have to be handled or canceled.

It also might be better to intercept the events from the form, rather than the document



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum