Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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

XML
<!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>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900