468,537 Members | 1,495 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Keycode change from Enter -> Tab Works, But Exception Needed

dlite922
1,584 Expert 1GB
got the following code that works great in IE, i have need an exception to these rules.

Why to Tab? Users come from old Apps (data entry people) and want to use the enter key to move through fields.

Works fantastic, however i have a text area now that they can't enter blank lines (paragraph breaks)

Expand|Select|Wrap|Line Numbers
  1.  
  2. document.onkeydown = checkKeycode
  3.    function checkKeycode(e) {
  4.     var keycode;
  5.     if (window.event) keycode = window.event.keyCode;
  6.     else if (e) keycode = e.which;
  7.  
  8.     if(keycode == 13){
  9.      event.keyCode=9;
  10.     }
  11.    }
  12.  
  13.  
what is the best way to modify this so that my text areas are exceptions to this rule.

I do not want to have to call a function onKeyUp/Down of each input field, there's a lot and i will miss some in development. (besides, it's messy)

By the way, Firefox compalins about event on line 8 above as being not defined, does that need to be "e.keyCode = 9" ??

Thanks
Jan 18 '08 #1
2 2413
acoder
16,027 Expert Mod 8TB
Use document.getElementByTagName("input") to get all the input elements, loop through the array and add the onkeydown event handler to each input by, e.g. inputs[i].onkeydown = ...
By the way, Firefox compalins about event on line 8 above as being not defined, does that need to be "e.keyCode = 9" ??
For cross-browser event handling, use something like:
Expand|Select|Wrap|Line Numbers
  1. if (!e) var e = window.event;
and then replace 'event' with 'e'.
Jan 18 '08 #2
dlite922
1,584 Expert 1GB
Use document.getElementByTagName("input") to get all the input elements, loop through the array and add the onkeydown event handler to each input by, e.g. inputs[i].onkeydown = ...
For cross-browser event handling, use something like:
Expand|Select|Wrap|Line Numbers
  1. if (!e) var e = window.event;
and then replace 'event' with 'e'.
understood, i'll try it and let you know.

as for the keyCode, yeah i know there's a cross-browser version, used it before i'll find it.

thank you.
Jan 21 '08 #3

Post your reply

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

Similar topics

1 post views Thread by Patrick Gibbons | last post: by
8 posts views Thread by oeyvind toft | last post: by
6 posts views Thread by Z | last post: by
6 posts views Thread by Justin Beasley | last post: by
4 posts views Thread by Thomas Christensen | last post: by
2 posts views Thread by Peter Proost | last post: by
1 post views Thread by Paul Nathan | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.