I have two textareas - one for pasting some text in it, the other is for inserting words from the first textarea after doubleclicking on them. How can I make it happen?
I've already achieved some result on the following case: 1.Paste some text into textarea 2.Double click on the word from textarea 3.See how this word appears in a div with ul inside. The word adds as a li. See the code of the case:
//html block
<textarea name="" id="text" cols="30" rows="10" ondblclick="copyPaste()" >Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur minus iure suscipit quam expedita? Sed minus laboriosam natus quaerat autem enim accusantium, architecto officiis aliquam pariatur. Adipisci provident tenetur velit!</textarea>
<div id="wordList" class="wordListclass">
<ul id="myList">
<li></li>
</ul>
</div>
</body>
//js block for copy-pasting words after doubleclick on the text from the texarea with id ='text'
"use strict";
function copyPaste(){
var selection = window.getSelection();
console.log(selection.toString());
var node = document.createElement("LI");
var selectionWithButton = selection;
var textnode = document.createTextNode(selectionWithButton);
node.appendChild(textnode);
document.getElementById("myList").appendChild(node);
}
Now I need to get rid of and add the second textarea. I want to see how words after doublclicking on the text from the first textarea appear in the second textarea. Important note - they should have the following structure:
word1
word2
word3
without html tags, because after I see the list of these words in the second textarea I want to insert them into a database, so html tags (as in the code I provided) would be undesirable. Replacing div element with textarea just didn't work, unfortunately. Thanks everyone for reading and help!