4

I want to append text inside Textarea. The text should be appended immediate after the cursor position and not at the end.

Here is my code:

The 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>

The Script:

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

The above code is live at: http://jsfiddle.net/zGrkF/

Thanks in advance..

prajan
  • 189
  • 2
  • 13

2 Answers2

1

Try jQuery.

With that the code is the following:

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

OR

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

UPDATED:

Try this link

Kicsi Mano
  • 3,551
  • 3
  • 21
  • 26
  • you don't need to load a whole library to do this as simple as that – Teneff Jun 17 '11 at 11:40
  • 1. click the button and the text 'blah test 123' appends inside text area. 2. In text area, now click inside and place the cursor after 'blah'and Click the button again. 3. Now the textarea will have 'blah test 123blah test 123'. All i want is that the textarea value should be 'blahblah test 123 test 123' as the cursor is after 'blah' text, the text should append immediate after it. – prajan Jun 17 '11 at 11:52
0

The jQuery Field Selection plugin is quite old but should enable you to do everything you want and more.

Town
  • 14,706
  • 3
  • 48
  • 72