Solved

Web Form: Automatically move the focus to next control

Posted on 2003-11-23
3
580 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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