Solved

Web Form: Automatically move the focus to next control

Posted on 2003-11-23
3
578 Views
Last Modified: 2012-06-27
VB.NET
Web Forms

Part of my web form contains three textbox server controls into which the user enters a U.S. telephone number. The first textbox is for the 3-digit area code (tbAreaCode), the second textbox holds the 3-digit exchange (tbExchange), and the third textbox holds the last 4 digits of the phone number (tbNumber).  So the three controls on the form are arranged to look something like this:

Phone Number:   ( _ _ _ ) _ _ _ - _ _ _ _


I have set the MaxLength for each text box to either 3 or 4 to limit input to the appropriate number of digits. Once they type the last digit in a text box I want the focus to immediately move to the next textbox in the tab order.

I cannot find any method that looks like SetFocus or MoveNext. How do I do it? (If it requires JavaScript, please give me a complete answer as I do not know Javascript.)
0
Comment
Question by:rgrimm
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 250 total points
ID: 9807848
rgrimm,

Try this, use onKeyUp JS function to get it work.:

<%@ Page Language="vb" %>
<script runat="server">
    Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Put user code to initialize the page here
        'register javascript event
        txt1.Attributes.Add("onkeyup", "javascript:tabNext('txt1','txt2')")
        txt2.Attributes.Add("onkeyup", "javascript:tabNext('txt2','txt3')")
    End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>tab</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
            <script language="javascript">
            function tabNext(obj,objNext)
            {
                  if((document.getElementById(obj).value).length==3)
                  {
                        document.getElementById(objNext).focus();
                        document.getElementById(objNext).select();
                  }
                  
            }
            </script>
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="frmSubmit" method="post" runat="server">
                  Phone Number :
                  <asp:textbox id="txt1" runat="server" maxlength="3" columns="3"/>
                  -<asp:textbox id="txt2" runat="server" maxlength="3" columns="3"/>
                  -<asp:textbox id="txt3" runat="server" maxlength="4" columns="4"/>
            </form>
      </body>
</HTML>

Regards
x_com
0
 

Author Comment

by:rgrimm
ID: 9812394
x_com,

Excellent! It worked great the first time. Thank you very much for taking the time to help me with this. I greatly appreciate it.

Sincerely,

Rick
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9814970
Glad to help, rgrimm.

Regards
x_com
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question