This is a migrated thread and some comments may be shown as answers.

RadMaskedTextBox Change The Focus Automatically

1 Answer 94 Views
Input
This is a migrated thread and some comments may be shown as answers.
Felipe
Top achievements
Rank 1
Felipe asked on 29 Jul 2011, 03:05 PM
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

1 Answer, 1 is accepted

Sort by
0
Pavel
Telerik team
answered on 03 Aug 2011, 08:28 AM
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.

Tags
Input
Asked by
Felipe
Top achievements
Rank 1
Answers by
Pavel
Telerik team
Share this question
or