On Oct 7, 8:23 pm, VJ <[email protected]> wrote: > > So, for example, suppose the textarea contains "Now is | time" and you > want to insert "the" at the cursor position and reposition the cursor > after it: > > var domEl = jQuery('textarea').get(0); > var cStart = domEl.selectionStart; > var cEnd = domEl.selectionEnd; > var newText = domEl.value.substring(0,cStart) + "the"; > newText += domEl.value.substring(cEnd); > domEl.value = newText; > cEnd += 3; > domEl.setSelectionRange(cEnd,cEnd); > > Hope that helps, > Jon >
Thank you, Jon. It works exactly as I desired. However, how do I return the focus back to the text area, after I click the button to insert a string? I tried the following and it did not work: domEl.focus(); I need to return the focus to the textarea so that after I insert the text, I can select the text inserted using: domEl.select(cBegin, cEnd); But, thanks for your suggestion and code, I have what I wanted in the first place! Cheers; 'best, shankar -- You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/tiddlywikidev?hl=en.
