Tuesday, January 12, 2010

Setting Cursor to End of the Text Box in java script // Asp.net


ShareThis
Setting Cursor to End of the Text Box in java script / Asp.net

1. Declare this function in Head section of ur html/ php /asp.net page

Setting Cursor to End of the Text Box in java script / Asp.net


<script type="text/javascript"></div><div> function SetCursorToEnd(TB) {</div><div> if (TB.createTextRange) {</div><div> var FieldRange = TB.createTextRange();</div><div> FieldRange.moveStart('character', TB.value.length);</div><div> FieldRange.collapse();</div><div> FieldRange.select();</div><div> }</div><div> }</div><div> </div><div> </script>


2.call this function like this


ASP.net

<asp:TextBox onfocus="SetCursorToEnd(this)" ID="txtRate" runat="server" ></asp:TextBox>

HTML

<input type="textbox" onfocus="SetCursorToEnd(this)" id="something" />

0 comments: