RadMaskedTextBox Change The Focus Automatically

2 posts, 0 answers
  1. Felipe
    Felipe avatar
    3 posts
    Member since:
    Jul 2011

    Posted 29 Jul 2011 Link to this post

    I have 3 controls 'RadMaskedTextBox': DDI, DDD and TEL
    When the user type the DDI, the control must change the focus automatically to the next control (DDD), and so on.

    Below is my code


    JavaScript
    function Next(field, max, next) {
        if (document.getElementById(field).value.length >= max) {
            document.getElementById(next).focus();
        }
    }

    ASPX
    <telerik:RadMaskedTextBox ID="txtDdiTel" runat="server" Mask="###"
             PromptChar="_" ResetCaretOnFocus="True" Width="35px" >
    </telerik:RadMaskedTextBox>
     
    <asp:Label ID="lblDdiTel" runat="server" Text="-"></asp:Label>
     
    <telerik:RadMaskedTextBox ID="txtDddTel" runat="server" Mask="###"
             PromptChar="_" ResetCaretOnFocus="True" Width="35px" >
    </telerik:RadMaskedTextBox>
                     
    <asp:Label ID="lblDddTel" runat="server" Text="-"></asp:Label>
     
    <telerik:RadMaskedTextBox ID="txtTel" runat="server" Mask="####-####"
             PromptChar="_" ResetCaretOnFocus="True" Width="80px" >
    </telerik:RadMaskedTextBox>


    VB.NET
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack Then
                txtDdiTel.Attributes.Add("onKeyPress", "Next('" & txtDdiTel.ClientID & "', '3', '" & txtDddTel.ClientID & "')")
                txtDddTel.Attributes.Add("onKeyPress", "Next('" & txtDddTel.ClientID & "', '3', '" & txtTel.ClientID & "')")
            End If
    End Sub


    But when I type 3 numbers, occurs the following error:
    htmlfile: Can not move focus to the control because it is invisible, not enabled or of a type that does not accept focus.

    Can Someone help me?

    Thanks,
    Felipe Almeida
  2. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 03 Aug 2011 Link to this post

    Hello Felipe,

    Try changing your script as follows:
    function Next(field, max, next)
    {
        if (document.getElementById(field).value.length >= max)
        {
            $find(next).focus();
        }
    }


    Greetings,
    Pavel
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top