Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / jQuery

Tab focus of textbox in ASP.NET using jQuery

1.00/5 (1 vote)
15 Aug 2013CPOL 14.7K  
Auto Tab focus to next textbox control in ASP.NET using jQuery.

Introduction

When user presses the Enter key, the Tab focus of a textbox moves to the next textbox using jQuery in ASP.NET.

Using the Code

Write this code in the Head tag of a webpage:

JavaScript
<script src="Scripts/jquery-1.9.1.js" 
      type="text/javascript"></script> 
<script type="text/javascript" language="javascript">
$(document).ready(function () 
{
    $('input:text:first').focus();
    $('input:text').bind('keydown', function (e) 
    {             
        if (e.keyCode == 13) 
        {                  
            e.preventDefault();
            var nextIndex = $('input:text').index(this) + 1;
            var maxIndex = $('input:text').length;
            if (nextIndex < maxIndex)
            {
                $('input:text:eq(' + nextIndex + ')').focus();
            }
        }
    });
});
</script>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)