Insert selected text on the page into textarea (jQuery)?

JQuery(function() { // Bind the click handler of some button on your page jQuery('#someButton'). Click(function(evt) { // Insert the selected text into a given textarea var textarea = jQuery('textarea#someTextArea'); textarea. Val(textarea.val() + getSelectedText()); evt.preventDefault(); }); }); // Get user selection text on page function getSelectedText() { if (window.

GetSelection) { return window.getSelection(); } else if (document. Selection) { return document.selection.createRange(). Text; } return ''; }.

This works, but if textarea already have some text, the function removes it with a selected text. How can I fix this? – Mike May 2 '09 at 17:27 I mean it must "to add" text info textarea, not "to replace".

– Mike May 2 '09 at 17:29 >it must add text into textarea without replacing – Mike May 2 '09 at 17:33 I modified my post accordingly – Darin Dimitrov May 2 '09 at 17:34 is it possible to insert not a simple text, with some tag within? For example, we are selecting word "Darin", pushing the button "#someButton" and it adds the "Darin" into textarea with a tag "q" -"qDarin/q"? – Mike May 2 '09 at 17:36.

You can do something like this: Copy the selected text you can use some jquery plugin listed here. Paste it inside a textarea: $('#textareaselector'). Text(selectedText).

This page doesn't work - laboratorium.0xab. Cd/jquery/fieldselection/0.2.3-test/test. Html – Mike May 2 '09 at 17:22 corrected the url.

Check again please – eKek0 May 2 '09 at 18:18 thanks, but I don't know how to use it :) – Mike May 2 '09 at 18:43.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions