Reputation: 229
I am trying to set the cursor position in a textarea using 'selectionStart' property. But while executing the line "element.selectionStart = 6", IE [9/10/11] gives an error "Could not complete the operation due to error 800a025e".
if (typeof element.selectionStart !== 'undefined') {
element.selectionStart = aCursorPosition;
element.selectionEnd = aCursorPosition;
}
I tried to put a debug point right before this line and tried to add a watch expression which will set the 'selectionStart' to '0' but event this results the same error.
The textarea in concern is loaded view Ajax response. The same piece of code works fine when the textarea is rendered normally.
Any clue how to solve it?
Upvotes: 1
Views: 678
Reputation: 229
Solved it by resetting the focus. I was setting the focus to textarea, before trying to set the cursor position, but it seems when the textarea is updated by Ajax, doing it is not enough.
I added code to set the focus to one of the nearest anchor tags and set the focus back to textarea again [I had to do it [focus reset] twice to make it work]. This seems to solve my problem.
Below given post and links helped gain some insights into the issue.
Upvotes: 1