I am trying to duplicate some of the "AutoCorrect" functionality seen in programs such as Microsoft Office Outlook.
To start, when the user enters "a" (letter a and a space) at the beginning of the line, I want to change this text to "* Agent ["
I wrote below, which works great if you type in the text box from top to bottom. But if you type somewhere else in the text box the text changes, the cursor moves to the end of the text box.
I want the cursor to always be at the end of the modified text.
I have the line number that was changed in the currentLineNumber variable, and I know that the cursor should be after the eighth character in this line, but I'm not sure how to tell it to go there
Ideally, id looks like something like
function setCursor(row, position) {
What can I do for this? I am open to javascript or jQuery solution (although I find jQuery a bit difficult to read and understand)
If there is a better way to achieve what I need as a whole, I am also open to this.
Here's jsFiddle if you don't understand the problem
javascript jquery textselection cursor textarea
DelightedD0D
source share