Usable Asp.Net

Little things that make Asp.Net more usable

Data Entry: Use Enter as Tab

A simple javascript will make your Enter key work as Tab. It is useful in large tabular forms.

function enterToTab(){
  if (event.keyCode==13)
    event.keyCode=9;
  }

<input type="text" onkeydown="enterToTab()">

Note using onkeydown event. Onkeypress won't do the trick.

Posted: Jul 30 2007, 03:25 PM by egoldin | with 4 comment(s)
Filed under:

Comments

ulrik said:

How do I do this for an asp.net form? I am using asp:TextBox which does not have an "onkeydown" argument.

Thanks

# January 29, 2009 1:56 PM

egoldin said:

You can pass any attribute to a web control in the Attributes collection:

myTextBox.Attributes["onkeydown"]="enterToTab()";

In fact, you can even put it in the markup and ignore the validation error. Asp.Net passes all arguments that it doesn't recognize to the html output:

<asp:TextBox ... onkeydown="enterToTab()"/>

# January 31, 2009 3:48 PM

Rene D. said:

Excellent solution!! thanks

# February 25, 2009 6:25 PM

Lenny said:

this only works with IE  :(

# June 8, 2009 3:18 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)