Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2008
    Thanked 0 Times in 0 Posts

    Question Hacking Return Key to Tab, then Space on Button

    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;
                evt.keyCode = 32;
                return evt.keyCode;
    Last edited by insidion; 05-06-2008 at 06:17 PM.

  2. #2
    Regular Coder
    Join Date
    Mar 2006
    Thanked 132 Times in 123 Posts
    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
    Last edited by mrhoo; 05-06-2008 at 07:27 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts