views:

29

answers:

1

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

+1  A: 

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]);
just somebody
Unfortunately that doesn't work if the user has simply placed her cursor on a line, rather than having actually created a selection. Would work just fine for the selections, however. :)
Dustin Hansen
Thats a Great Response from somebody :).I am bit Confused here, Can you please explain me How it works and what are the arguments.. Sorry if its silly, I am new to JS :)
CFUser
Main main doubt is "var $t = $('#query-textarea');" How its getting from Text Area in JS?
CFUser
with jQuery (http://www.jquery.com/)
just somebody
It Worked for me, Thank you Very much...
CFUser