3

I want to quote the selected text in a textentry field in a form in the traditional email manner, prefixing every line with ">". (It happens to be for Bugzilla today, not that it makes a difference or anything.)

I suspect that it might be possible to adapt the code from Bookmarklet Help: Creating a Find/Replace Bookmarklet or its predecessor Find all instances of 'old' in a webpage and replace each with 'new', using a javascript bookmarklet, but I'm not too sure how to apply this to a selection …

(I might be over thinking things, because I keep getting dizzy thinking about selections spanning elements when that's clearly not actually relevent.)

Community
  • 1
  • 1
SamB
  • 9,039
  • 5
  • 49
  • 56
  • Not up to providing real answer, but I'll point you in right direction: google 'javascript modify textarea value' and 'javascript get selected text from textarea'. Then its a simple case of `str = '> ' + str.split('\n').join('\n> ')`. Write your solution first in normal js, then convert to a bookmarklet. Google 'bookmarklet creator'. – DG. Jan 20 '14 at 01:02
  • Yes, I am aware that I don't want to try to write it directly as a bookmarklet :-P. – SamB Jan 20 '14 at 01:04
  • Hmm, I'm having trouble with the test harness: clicking on my test button seems to reset my selection before it does `onclick` ... – SamB Jan 20 '14 at 02:05

0 Answers0