Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8727481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:26:31+00:00 2026-06-13T08:26:31+00:00

I have an ASP.NET web forms project that I am trying to implement auto-tabbing

  • 0

I have an ASP.NET web forms project that I am trying to implement auto-tabbing in. I’m new to jquery, but I found a code snippet online to do auto-tabbing, and I want to use it to autotab multiple groups of textboxes.

For example:

Textbox1 -> Textbox2 -> Textbox3

Textbox4 -> Textbox5 -> Textbox6

But not:

Textbox3 -> Textbox4

Hope that makes sense. Anyway, I have the following code:

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(".autotab").keyup(function () {
            if ($(this).attr("maxlength") == $(this).val().length) {
                var index = $(".autotab").index(this);
                var item = $($(".autotab")[++index]);
                if (item.length > 0)
                    item.focus();
            }
        });
        $(".autotab2").keyup(function () {
            if ($(this).attr("maxlength") == $(this).val().length) {
                var index = $(".autotab2").index(this);
                var item = $($(".autotab2")[++index]);
                if (item.length > 0)
                    item.focus();
            }
        });
    });
</script>

<input name="tbOne" type="text" maxlength="3" id="tbOne" class="autotab" />
<input name="tbTwo" type="text" maxlength="3" id="tbTwo" class="autotab" />
<input name="tbThree" type="text" maxlength="4" id="tbThree" class="autotab" />

<input name="tbFour" type="text" maxlength="3" id="tbFour" class="autotab2" />
<input name="tbFive" type="text" maxlength="3" id="tbFive" class="autotab2" />
<input name="tbSix" type="text" maxlength="4" id="tbSix" class="autotab2" />

How can I refactor the copy/pasted code into a single function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:26:32+00:00Added an answer on June 13, 2026 at 8:26 am

    A more general solution, that doesn’t require that you use one class per group:

    // loop through adjacent pairs
    $.fn.eachPair = function(f) {
        for(var i = 0, j = 1; j < this.length; i = j++)
            f.call(this[i], this[j]);
    }
    
    $.fn.autotab = function() {
        this.eachPair(function(next) {
            // add an event handler to focus the next field
            $(this).keyup(function() {
                if($(this).attr("maxlength") == $(this).val().length)
                    $(next).focus();
            });
        });
    }
    
    $(document).ready(function () {
        $(".autotab").autotab();
        $(".autotab2").autotab();
    });
    

    As a side note, the $($(".autotab2")[++index]) in your code would have been better written as $(".autotab2").eq(index + 1)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Asp.Net 4.0 Web Forms project that uses url routing for user
I have a asp.net web forms app that uses System.Web.Caching.Cache to cache xml data
I have an ASP.NET 4 Web Forms app that is using URL Routing. I
I have an ASP.NET web application that is using forms authentication. Everything is configured
I have an existing Web Site that uses multiple ASP .Net Web Forms projects.
I have an ASP.Net 4.0 web forms application that is ignoring any changes I
In my ASP.NET Web-form Project I have an Event which Export Data ( List<Profit>
I have a ASP.NET Web Forms application and I'm using some dynamic controls in
I have an ASP.NET Web Forms web site. It has a page inside of
I have now 3 hours of experience (tryence) in ASP.NET Web Forms. I'm so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.