Geeks With Blogs


Microsoft MVP


Moderator at CodeASP.NET

Quiz Master

free counters
Free counters
Added on January 19,2012

Follow Me @vmsdurano

A bit About Me

The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.

Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

There are times that we need to use the enter key instead of using the Tab key for moving the focus of the TextBox controls from one to another to perform rapid data entry in the page. This example shows on how to achieve that with the use of JavaScript.

Here are the code blocks below:


<html xmlns="" >

<head id="Head1" runat="server">



<script type="text/javascript" language="javascript">

 function controlEnter (obj, event)


     var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;     

     if (keyCode == 13)



        return false;     


     else  {

        return true;





    <form id="form1" runat="server">

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

    <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>

    <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>






protected void Page_Load(object sender, EventArgs e)


         TextBox1.Attributes.Add("onkeypress", "return controlEnter('" + TextBox2.ClientID + "', event)");

         TextBox2.Attributes.Add("onkeypress", "return controlEnter('" + TextBox3.ClientID + "', event)");

         TextBox3.Attributes.Add("onkeypress", "return controlEnter('" + TextBox4.ClientID + "', event)");

         TextBox4.Attributes.Add("onkeypress", "return controlEnter('" + TextBox5.ClientID + "', event)");

         TextBox5.Attributes.Add("onkeypress", "return controlEnter('" + TextBox1.ClientID + "', event)");



That’s it! Hope you will find this example useful!

Technorati Tags: ,,
Posted on Monday, June 22, 2009 9:09 PM ASP.NET , JavaScript , Tips&Tricks | Back to top

Comments on this post: Move TextBox Focus when Hitting Enter Key.

# re: Move TextBox Focus when Hitting Enter Key.
Requesting Gravatar...
i want same code in please provide some information
Left by kesav on Aug 24, 2012 8:37 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: