I understand that with javascript you can select the contents of a textbox with the following code (in jQuery):
$(\"#txt1\").select();
Is t
You need to set the selectionStart
and selectionEnd
attribute. But for some reason, setting these on focus event doesn't work (I have no idea why). To make it work, set the attributes after a small interval.
$(document).ready(function(){
$('#txt1').focus(function(){
setTimeout(function(){
// set selection start, end to 0
$('#txt1').attr('selectionStart',0);
$('#txt1').attr('selectionEnd',0);
},50); // call the function after 50ms
});
});