Is it possible to change cursor position in textarea element using Javascript code?
Asked
Active
Viewed 3,306 times
0
-
Possible duplicate of http://stackoverflow.com/questions/5140637/javascript-how-to-get-line-col-caret-position-in-textarea – n00dle May 26 '11 at 15:56
2 Answers
2
YES
function SetCursorPosition(pos)
{
// HERE txt is the text field name
var obj=document.getElementById('<%= txt.ClientID %><%= txt.ClientID %>');
//FOR IE
if(obj.setSelectionRange)
{
obj.focus();
obj.setSelectionRange(pos,pos);
}
// For Firefox
else if (obj.createTextRange)
{
var range = obj.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
FROM :: http://shawpnendu.blogspot.com/2009/03/javascript-how-to-setget-cursor.html

Shikiryu
- 10,180
- 8
- 49
- 75

Barkermn01
- 6,781
- 33
- 83
1
This post may help you Caret position in textarea, in characters from the start
-
And this one http://stackoverflow.com/questions/3286595/update-textarea-value-but-keep-cursor-position – Ishmael May 26 '11 at 15:58