Add Text to TextArea

I want to add text inside Textarea. Text should be added immediately after the cursor position, and not at the end.

Here is my code:

HTML:

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <textarea id="textarea1"></textarea> <br><input type="button" value="Write blah blah" onclick="addtxt('textarea1')"> </body> </html> 

Script:

 <script> function addtxt(input) { var obj=document.getElementById(input); obj.value+="blah test 123" } </script> 

The above code is in real time: http://jsfiddle.net/zGrkF/

Thanks in advance.

+4
source share
2 answers

Try jQuery .

The code is as follows:

 $("#textarea1").hover( function() { $(this).value('IN'); }, function() { $(this).value('OUT'); }); 

OR

 $("#textarea1").mouseover( function() { $(this).value('IN'); }); 

UPDATED:

Try the link

+1
source

The jQuery field select plugin is pretty old, but should allow you to do whatever you need and more.

0
source

All Articles