Click here to Skip to main content
14,390,210 members
Rate this:
Please Sign up or sign in to vote.
See more:
<textarea name="text1"></textarea>
<input type="button" value="Add Text" onClick="addText1();">


Say I have a text area as the one above, and a button.
I want to highlight text within the text area, and at the press of a button it adds text infront of the selection.

Is this possible?

I've researched a bit online and this is the closest thing I found: Link


Thanks,
L.
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Yes you can. See below, where I have grabbed the textbox value and concatenates it with an additional value.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <title>Test</title>

<script type="text/javascript">
function addText1()
{
    document.test.text1.value = document.test.text1.value + " THIS IS EXTRA! "
}
</script>
 </head>

 <body>
 <form name="test">
  <textarea name="text1"></textarea>
    <input type="button" value="Add Text" onClick="addText1();">
</form>
 </body>
</html>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100