So, currently I have a text-input-field with a value that is also autofocused.
On page load, the value is selected / highlighted. Is there a way I can put the cursor at
Use Jquery for this:
$(function() {
var input = $("#txt1");
var len = input.val().length;
input[0].focus();
input[0].setSelectionRange(len, len);
});
But some browsers don't support enter code here
property, in which case use this:
$(document).ready(function(){
$("#search").focus(function(){
if (this.setSelectionRange)
{
var len = $(this).val().length;
this.setSelectionRange(len, len);
}
else
{
$(this).val($(this).val());
}
});
$("#search").focus();
});
This question already exist on stackoverflow:
Reference1
Reference2