user2525550
user2525550

Reputation: 21

Textarea Selected Text Drag and Drop Copy

I want the users of my application to be able to highlight text from a textarea and drag and drop it into a text input.

I want to change the default behavior (the user shouldn't have to hold down CTRL or ALT) to copy the text rather than being moved from the textarea to the input.

I've already tried using jQuery Draggable and Droppable. I could see how this would work if a div or a static static would be selected and a helper clone was used, but I don't know how to do it with a random text selection in a textarea.

Upvotes: 2

Views: 2358

Answers (1)

Jarek.D
Jarek.D

Reputation: 1294

You could try the following hack:

  1. On select create a transparent div and copy the selected text into it, with something like 'window.getSelection'
  2. Make the div Draggable and Droppable
  3. On drop get the content from the div, populate the input field and clear the div

Upvotes: 1

Related Questions