Tags: asp, auto-tab, code, example, forms, net, number, script, telephone, textboxes, time-consuming, web

Auto-tab in textboxes

On .Net » Web Forms

2,586 words with 8 Comments; publish: Fri, 04 Jan 2008 08:55:00 GMT; (10062.50, « »)


This may be a simple question but for me it is time-consuming to look for ASP.NET code/script for the telephone number textboxes.

For example, first textbox is area code, second textbox is 1st three digits and third textbox is the last 4 digits. How do I make the cursor automatically tab to the second textbox after I finish inputting the area code WITHOUT using the Tab Key ? I know there are some codes in Javascript, but I want ASP.NET code.

Many thanks!


All Comments

Leave a comment...

    • Javascript is best suited for this because the code has to run client side, since the .net code has no idea what or how many characters the user is entering in because it has already pushed the page to the client.
      #1; Fri, 04 Jan 2008 08:56:00 GMT
    • Thanks, optik. That is what I still believe client side checks the input right away rather than going to the server side to waste time and performance.
      #2; Fri, 04 Jan 2008 08:57:00 GMT
    • Hi!!!

      I am interesting in this solution. Do you have the code to do this? Thanks

      #3; Fri, 04 Jan 2008 08:59:00 GMT
    • Hi !!!

      Thanks for reply!!!

      OK, that is fine , can i have code and could you tell me where did you place it?

      #4; Fri, 04 Jan 2008 09:00:00 GMT
    • I do have a code with Javascript, but not ASP.NET.


      #5; Fri, 04 Jan 2008 09:00:00 GMT
    • Click on this link: http://www.javascriptkit.com/script/script2/autotab.shtml

      OR use this below:

      Simply insert the below in the <body> section of your page:



      Auto tabbing script- By JavaScriptKit.com


      This credit MUST stay intact for use


      function autotab(original,destination){

      if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))




      Below this code must be after <BODY

      Enter your 10-digit phone number:

      <form name="sampleform">

      <input type="text" name="first" size=4 onKeyup="autotab(this, document.sampleform.second)" maxlength=3> <input type="text" name="second" size=4 onKeyup="autotab(this, document.sampleform.third)" maxlength=3> <input type="text" name="third" size=5 maxlength=4


      As shown in the sample form, the key to adding auto tabbling to a form field is through the code in red:

      <input type="text" name="first" size=4 onKeyup="autotab(this, document.sampleform.second)" maxlength=3

      Change "document.sampleform.second" to reference the field to auto tab to, and "maxlength" to specify the source field's character limit.

      #6; Fri, 04 Jan 2008 09:02:00 GMT
    • Hi !!

      Thank you for your reply put can i ask one question!!!

      Is is possible to approach the same behaviour when using asp:TextBox (server control) rather than input (html control)

      #7; Fri, 04 Jan 2008 09:03:00 GMT
    • You can try ! I think it is possible.


      #8; Fri, 04 Jan 2008 09:04:00 GMT