Possible Duplicate:
Inserting a text where cursor is using Javascript/jquery
How do I add text to a textarea at the cursor location using javascript
I currently have a working method of adding to a textarea based off of clicking on objects with the class=".module"
My problem is its just adding to the end and I need a way for it to add to where my cursor is or something of that nature so users can add modules at anytime anywhere in the text area.
Example of my code:
Sets the value of the textarea "email-body" to be it + the module
$(".module").live('click', function() {
$('#email-body').val($('#email-body').val()+$(this).val());
});
This is my email body & modules
<button class="module" value="1">Button 1</button>
<button class="module" value="2">Button 2</button>
<textarea id="email-body" name="email-body"></textarea>