0

I have written below code to set focus to the end of text in the textbox :

var textbox = document.getElementById('txtFilter');
textbox.focus(); 
textbox.value = textbox.value; 

But I am facing a problem here. When i keep typing fastly, newly typed characters are not appearing and it is displaying the old value again and again. So I have to wait after pressing each key, then it works fine.

I found another piece of code to achieve this:

if (textbox.createTextRange) {               
var FieldRange = textbox.createTextRange();            
FieldRange.moveStart('character', textbox.value.length);
FieldRange.collapse();
FieldRange.select();
return false;
}    

But when I tried this, I am getting error - Could not complete the operation due to error 800a025e sometimes. Please help me. Any help will be appreciated.

Rajeev
  • 3
  • 4

1 Answers1

0

You can use

$('#txtFilter').focus(); //focus using jQuery (browser indipendent)
$('#txtFilter').caretToEnd(); // move position to the end

Unfortunately you need a plugin https://gist.github.com/DrPheltRight/1007907

Stefano Altieri
  • 4,550
  • 1
  • 24
  • 41