473,394 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 2623
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

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

Similar topics

1
by: Patrick Gibbons | last post by:
I would like to know what keycode # pertains to what keycode . . . This code allows a user to limit the entries in a form to only those keycodes they would like, #s only for US zip codes, for...
8
by: oeyvind toft | last post by:
How do I capture the ctrl keypress? Is it possible for js to intercept the ctrl-n combination and prevent the creation of a new IE window?? (Have 3 huge books on js and none of them mention...
6
by: Z | last post by:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a...
6
by: Justin Beasley | last post by:
Here is an answer for those who are looking for a keystroke evaluation script that works in Internet Explorer (IE 5.5, 6.0, 7.0 for PC--IE 4.0, 5.2 for Mac), Mozilla Firefox (Windows, Linux, and...
4
by: Thomas Christensen | last post by:
I'm trying to figure out what key the user pressed using a Danish keyboard layout. charCodeAt returns the correct number, but event.keyCode returns a wrong number, when using one of the keys that...
1
by: kids_pro | last post by:
Hi there, I want to capture the last key press in a textBox. So I decided to use KeyDown event and from the KeyEventArgs I read the e.KeyCode But when I type small letter the e.KeyCode always...
2
by: strah | last post by:
I am trying to detect when a user uses Tab key while with the KeyDown event of the combobox. It seems to work fine with all the Keys (Enter, T, ...) but not with the Tab key (e.KeyCode = Keys.Tab)....
2
by: Peter Proost | last post by:
Hi group, I want to verify if my problem also happens with other people, place a radiobutton, two textboxes, and a button on a form then copy paste this code run the prog and press enter on the...
1
by: Paul Nathan | last post by:
Further to my post about keyboard problems, I have discovered that Num Lock seems to change the e.keycode for the arrow keys and the 9 above them excluding scroll lock and pause-break. With Num...
5
Frinavale
by: Frinavale | last post by:
I have a some text inputs that expect numbers as input. I have written a function that returns false if any key other than one that represents a number is pressed. I call the function during the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.