Sunday, February 24, 2013

Click and Highlight Text in a ASP.NET TextBox using jQuery


.aspx MarkUp:

<div class="smallDiv">
<h2>Click in the text box to select all the text automatically</h2>
<asp:TextBox ID="tb1" runat="server" Text="Click Here to Select"/>
Tip: If you do not click and just start typing into textbox,
the effect does not show up
</div>

Jquery Script:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('input[id$=tb1]').click(function() {
$(this).focus().select();
});
});
</script>



No comments:
Write comments
Recommended Posts × +