Question

I want to submit part of a TextArea (User has entered Multiple Lines and selected one line either by Highlighting or by placing the cursor on the line). If user press the Submit Button then, I need to get the Line or word user has selected.

Just for my requirement Understanding See Below Example

Ex:- TOAD, SQL Server : where we can enter multiple Queries and When we press CTRL+Enter or F9 the selected Query only gets submitted to Database

Was it helpful?

Solution

did exactly that, for MS SQL Server 2005 ;)

var selected = window.getSelection
  ? function (s, t)
    {
        var sel = s.substring(
            t.selectionStart
          , t.selectionEnd
        );
        return sel.length ? sel : s;
    }
  : function (s, t)
    {
        var r = document.selection.createRange();
        return r.text && t == r.parentElement()
          ? r.text
          : s
        ;
    }
;

var $t = $('#query-textarea');
var query = selected($t.val(), $t[0]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top