c# - Focus textbox and position cursor on page load -
so want set cursor position end of textbox after page loaded. have code jquery:
<script src="http://code.jquery.com/jquery-latest.min.js"></script> <script src="https://rawgit.com/ichord/caret.js/master/src/jquery.caret.js"></script> <script type="text/javascript"> $(document).ready(function () { var textbox = $('#messagesbox'); textbox.focus(); textbox.caret('pos', textbox.val().length); }); </script> <asp:textbox id="messagesbox" runat="server" textmode="multiline" style="resize:none" readonly="true" width="300" height="200"></asp:textbox>
what missing? need set in code-behing well?
try :
$(document).ready(function(){ var el = $("#messagesbox"); var elemlen = el.value.length; el.selectionstart = elemlen; el.selectionend = elemlen; el.focus(); });
Comments
Post a Comment