469,366 Members | 2,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

javascript/ change enter key to tab keypress

this work great and stops all enter key presses. now how do i disable the event and fire a tab key event.
so if a user presses the enter key i need it to be ignore and tab to the next field.

<head>
<script type="text/javascript">

function kH(e) {
<!--
var pK = document.all? window.event.keyCode:e.which;
return pK != 13;
}

document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
file://-->
</script>
</HEAD>
Apr 27 '06 #1
8 107500
here is code that works! must be in body tag.
<body> onkeydown="if (event.keyCode==13) {event.keyCode=9; return event.keyCode }"
Apr 27 '06 #2
here is code that works! must be in body tag.
<body> onkeydown="if (event.keyCode==13) {event.keyCode=9; return event.keyCode }"
The above code was a lot help. But in my web page I have to also access the links using keyboard. In that case I have to use the alt + access key and then press enter to access a particular link. So if I use the above code then I am not able to access the links using keyboard.
Jun 1 '06 #3
This Code is Working Fine with all controls , means the Focus is moving to Next Control. BUT this is not working When the Focus is in "HtmlInput File"Control which we will use for File UpLoadings. means Focus is not moving to Next Control. Then How to modify code.


this work great and stops all enter key presses. now how do i disable the event and fire a tab key event.
so if a user presses the enter key i need it to be ignore and tab to the next field.

<head>
<script type="text/javascript">

function kH(e) {
<!--
var pK = document.all? window.event.keyCode:e.which;
return pK != 13;
}

document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
file://-->
</script>
</HEAD>
Feb 15 '07 #4
asipo
1
actually the code provide by rrosebro is not working for me =.=

and i try alot with that kind of coding where u try to set the 13 into 9

and i think the web browser ( im using mozilla firefox 2.0.0.14 ) not allowing us to change that

so heres my code to solve the enter as tab ( using an id as element )


at the script part
Expand|Select|Wrap|Line Numbers
  1.        function testing(event,number)
  2.     {
  3.         if( event.keyCode == 13 )
  4.         {
  5.             var wow = document.getElementById(number);
  6.             wow.focus();
  7.         }        
  8.     }

so the input will look like this
Expand|Select|Wrap|Line Numbers
  1. <form>
  2.           <input id="1" type="text" tabindex="1" onkeyup="testing(event,2)" />
  3.           <input id="2" type="text" tabindex="3" onkeyup="testing(event,3)" />
  4.           <input id="3" type="text" tabindex="2" onkeyup="testing(event,1)" />
  5. </form>
Jun 26 '08 #5
acoder
16,027 Expert Mod 8TB
Welcome to Bytes and thanks for sharing.

Remember that IDs should not start with or be only numbers, so use a string not starting with a number.
Jun 26 '08 #6
its too simple dear,
in body tag just add this
<body onkeydown="if (event.keyCode==13) {event.keyCode=9; return event.keyCode }">

DONE!.. :) Now your ENTER key will be treated as TAB key to focus other controls..

Regards
Sheryar Nizar
[url removed]
Jul 17 '08 #7
acoder
16,027 Expert Mod 8TB
Are you sure about that? Have you tested on browsers besides IE? What about textareas?

I've removed the link in your post. Please read the Posting Guidelines.
Jul 17 '08 #8
Logician
210 100+
this work great and stops all enter key presses. now how do i disable the event and fire a tab key event.
so if a user presses the enter key i need it to be ignore and tab to the next field.
Try using EnterToTab
Jul 17 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Marc Castrechini | last post: by
1 post views Thread by Tom S. | last post: by
3 posts views Thread by Bob Sanderson | last post: by
5 posts views Thread by Paul Lautman | last post: by
2 posts views Thread by newbiegalore | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.