By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

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

dlite922
Expert 100+
P: 1,584
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
Share this Question
Share on Google+
2 Replies


acoder
Expert Mod 15k+
P: 16,027
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
Expert 100+
P: 1,584
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.