Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    DJW
    DJW is offline
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't replace Keycode for <space> with <Tab>

    I have a 3 textareas that when the user presses the spacebar I would like for the code to execute a TAB to move between them instead. My code works if I make the replacement keycode an number or letter but it wont work if I use TAB. The browser is IE. Thank you for any help you can give.

    <script type="text/javascript">
    function keycode(e) {
    if(e.keyCode==32) {return (e.keyCode=9);}
    }
    </script>
    </head>
    <body>
    <form>

    <input name="DefectNumber" id="DefectNumber" type="text" onkeypress="return keycode(event);">
    <input name="DefectNumber2" id="DefectNumber2" type="text" onkeypress="return keycode(event);">
    <input name="DefectNumber3" id="DefectNumber3" type="text" onkeypress="return keycode(event);">
    </form>
    </body>
    Last edited by DJW; 09-15-2009 at 07:10 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,029
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    This will work in IE only:-

    <body onkeydown="if (event.keyCode==32) {event.keyCode=9; return event.keyCode }">

    Must be in <body> tag. Obviously that will apply to all fields.

    Another method is to use the focus method of the element you want to focus.

    Code:
    </head>
    <script type="text/javascript">
    function move2(ev) {
    var key;
    ev = ev || event;
    key = ev.keyCode;
    alert (key);
    if (key == 32) {
    document.forms[0].DefectNumber2.focus();
    return false;
    }
    }
    </script>
    </head> 
    <body> 
    <form>
    
    <input name="DefectNumber" id="DefectNumber" type="text" onkeyup ="move2(event)">
    <input name="DefectNumber2" id="DefectNumber2" type="text" onkeyup = "move3(event")>
    <input name="DefectNumber3" id="DefectNumber3" type="text" >
    </form>

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    DJW
    DJW is offline
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for your help.
    Your code put me on the right path. I have a <TD> tag calling a function where I manipulate the keycodes. I have one more question if you wouldn't mind. Is there a way to pass multiple keycodes? In other words if I press the spacebar I would like it to simulate the TAB key being pressed twice.

    Thank you again.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,029
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Quote Originally Posted by DJW View Post
    Your code put me on the right path. I have a <TD> tag calling a function where I manipulate the keycodes. I have one more question if you wouldn't mind. Is there a way to pass multiple keycodes? In other words if I press the spacebar I would like it to simulate the TAB key being pressed twice.
    What is the point of this, and why do you want to alter the default behaviour of the browser? When the user presses space, he expects to get a space, not a tab, still less two tabs. This sort of thing is guaranteed to annoy your users and drive them away from your site.

    If you insist, use the script I gave you to move the focus to whatever location seems to please you.

  • #5
    DJW
    DJW is offline
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This not a personal website it is a web-based test tracking tool that my company uses and there is no accelerator key capablity so I have tasked with creating them. I am actually not using the space bar I am using the down arrow, I was just looking for example help so that I could actually complete it myself.


  •  

    Posting Permissions

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