0

I want to keep the text selection when the textarea loses the focus.

For Internet Explorer and without any jQuery.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
shlomjmi
  • 667
  • 3
  • 12
  • 16
  • 4
    Why would you want to do this? This isn't what the user expects to happen. – Nick Craver Nov 14 '10 at 17:19
  • well, if i asked that probably I need it right? :) – shlomjmi Nov 14 '10 at 17:24
  • It's a lot of code, so I don't have the time to write up an answer here right now, but see http://stackoverflow.com/questions/1592637/keep-text-selection-when-focus-changes for an idea of how to do it (that example uses jQuery, but only for the event handling -- the text selection stuff is all plain javascript). – Ben Lee Nov 14 '10 at 17:30
  • You mean keep it visually, or just have CTRL+C copy into the clipboard the last selected text from the textarea? – Shadow The GPT Wizard Nov 15 '10 at 12:24
  • I mean when i return to text box, the selection of text should be as it was before. – shlomjmi Nov 17 '10 at 17:08

1 Answers1

0

If the selection needs to be visible only when the textarea has the focus, you could store the selected start and end, at onblur and at the next onfocus set it again.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mic
  • 24,812
  • 9
  • 57
  • 70