1

How could I get the selected text in the following code ?

I working with Firefox 3.6.3 (currently not interested in other browsers).

HTML:

<input id="my_text_field" type="text" />
<div id="log"></div>

JavaScript:

$("#my_text_field").select(function() {
   var selected_text = "Something selected"; // What should be here ?
   $("#log").append(selected_text + "<br />");
});
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
  • possible duplicate of [How to get selected text from textbox control with javascript](http://stackoverflow.com/questions/275761/how-to-get-selected-text-from-textbox-control-with-javascript) – karim79 May 17 '10 at 13:07

2 Answers2

2

Check out this other SO post. Hope this helps. ;)

How to get selected text from textbox control with javascript

Community
  • 1
  • 1
Lance
  • 5,655
  • 4
  • 30
  • 32
1

Have a look at this plugin:

http://labs.0xab.cd/jquery/fieldselection/0.2.3-test/test.html

  • Sad, its offline. Has anyone downloaded version 0.2.3 and is able to obtain it? EDIT: Found: http://alexcompiler.googlecode.com/svn-history/r6/trunk/javascript/jquery-fieldselection.js – mgutt Aug 22 '12 at 06:54
  • Ok, found again: http://www.programmierer-forum.de/jquery-fieldselection-by-alex-brem-v0-2-3-last-cange-2006-12-20-t316789.htm – mgutt Nov 14 '13 at 21:28