I'm wondering how I can insert text into a text area using jquery, upon the click of an anchor tag.
I don't want to replace text already in textarea, I want to append new text to textarea.
I'm wondering how I can insert text into a text area using jquery, upon the click of an anchor tag.
I don't want to replace text already in textarea, I want to append new text to textarea.
I like the jQuery function extension. However, the this refers to the jQuery object not the DOM object. So I've modified it a little to make it even better (can update in multiple textboxes / textareas at once).
This works really well. You can insert into multiple places at once, like:
Another solution is described also here in case some of the other scripts does not work in your case.
I use this function in my code:
It's not 100% mine, I googled it somewhere and then tuned for mine app.
Usage:
$('#element').insertAtCaret('text');
I know this is an old question but for people searching for this solution it's worth noting that you should not use append() to add content to a textarea. the append() method targets innerHTML not the value of the textarea. The content may appear in the textarea but it will not be added to the element's form value.
As noted above using:
will work fine.
Simple solution would be : (Assumption: You want whatever you type inside the textbox to get appended to what is already there in the textarea)
In the onClick event of the < a > tag,write a user-defined function, which does this:
(where the ids,textId1- for o/p textArea textId2-for i/p textbox')