Click here to Skip to main content
15,664,272 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai everyone,

I'm facing issue in changing the focus to another textbox if one textbox length reaches maxlength.

If it is a normal asp textbox it's changing its focus. But i'm using asp textbox which is masked with ajax using ajax control tool kit.


the code i'm using is

function changefocus(maxlength)
{
if(document.getElementById("<%=textbox1.ClientID%>").value.length==maxlength)
{
document.getElementById("<%=textbox2.ClientID%>").focus();
}
else
{
return;
}
}
When the length of textbox1 is equal to maxlength then it's clearing the content and focusing back in the same textbox1 but not changing the focus to textbox2. Please reply me the solution ASAP.

Thanks
Posted

1 solution

On your textbox, add an onkeypress JavaScript event and run a method in there:

<script type="text/javascript">
var maxLength = 100;
function CheckLength(textbox) {
    if(textbox.value.length >= maxLength) {
        document.getElementById("<%=textbox2.ClientID%>").focus();
        textbox.value = textbox.value.substring(0, maxLength);
    }
}
</script>

<asp:textbox id="textbox1" runat="server" onkeypress="CheckLength() />
<asp:textbox id="textbox2" runat="server" />
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900