Tuesday, November 15, 2011

Position cursor after all contents in Asp.Net TextBox

<asp:TextBox ID="TextBox1" runat="server"
onfocus="FocusAtLast();"
 ></asp:TextBox>

    function FocusAtLast () {
       
    var inputField = document.getElementById('<%= TextBox1.ClientID %>');
    if (inputField != null && inputField.value.length> 0)
    {
    if (inputField.createTextRange)
    {
    var FieldRange = inputField.createTextRange();
    FieldRange.moveStart('character',inputField.value.length);
    FieldRange.collapse();
    FieldRange.select();
    }
    }
    }

Reference:

http://msdn.microsoft.com/en-us/library/ms535872%28v=VS.85%29.aspx

No comments:

Post a Comment