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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

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

    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)

    Code:
      
    document.onkeydown = checkKeycode
       function checkKeycode(e) {
    	var keycode;
    	if (window.event) keycode = window.event.keyCode;
    	else if (e) keycode = e.which;
    	
    	if(keycode == 13){
    	 event.keyCode=9;
    	}
       }
    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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use document.getEle mentByTagName(" 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 = ...
    Originally posted by dlite922
    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:[code=javascript]if (!e) var e = window.event;[/code] and then replace 'event' with 'e'.

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      Originally posted by acoder
      Use document.getEle mentByTagName(" 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:[code=javascript]if (!e) var e = window.event;[/code] 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.

      Comment

      Working...