The following code sets the focus on a specific textbox when the page loads. How do I select all the text in the textbox?
<script type="text/javascript">
$(document).ready(function () {
$(function () {
var isPostBack = $("#IsPostBack").val();
if (isPostBack == 'True') {
$('#MyElement').focus();
}
});
});
</script>
Using function () { $(this).select(); }
inside focus
doesn't seem to work for me. In fact, it prevents the textbox from being selected at all.
As per another post, I tried the following but it did not work.
$(document).ready(function () {
$(function () {
var isPostBack = $("#IsPostBack").val();
if (isPostBack == 'True') {
$('#Pupils4YOPreK').focus(function () { $(this).select(); });
}
});
});