javascript - set cursor to specific position on specific line in a textarea -
i trying duplicate "autocorrect" functionality seen in programs microsoft office's outlook.
for starters, anytime user types "a " (the letter , space) @ beginning of line want change text "*agent ["
i have written below works fine if typing along in textarea top bottom. but if type anywhere else in textarea text changed cursor moves end of textarea.
i want cursor placed @ end of changed text.
i have line number changed in variable currentlinenumber
, know cursor needs after 8th character in line unsure of how tell go there
ideally id
function setcursor(row, position) { //.... code set cursor }
what can accomplish this? im open javascript or jquery solution (although find jquery little difficult read , understand)
if there's better way achieve need overall, i'm open too.
here's jsfiddle if don't understand issue
i've updated fiddle see: http://jsfiddle.net/eghpf/2/
i've added var currentposition
used in method
function setselectionrange(input, selectionstart, selectionend) { if (input.setselectionrange) { input.focus(); input.setselectionrange(selectionstart, selectionend); } else if (input.createtextrange) { var range = input.createtextrange(); range.collapse(true); range.moveend('character', selectionend); range.movestart('character', selectionstart); range.select(); } }
which comes jquery set cursor position in text area
what happens (is reason why cursor on last position); when call $('#systemnotesbuilder').val(arrayoflines.join("\n"));
entire value gets overwritten new value placing cursor after new value. call set cursor (and should) after call.
Comments
Post a Comment