Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Web Form: Automatically move the focus to next control

Posted on 2003-11-23
3
Medium Priority
?
593 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 1000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

636 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