Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert text into a textarea....

Status
Not open for further replies.

adamsoderqvist

Programmer
Sep 8, 2001
136
SE
Is there a way of inserting text snippets into a HTML text area?

Lets say I have a <textarea></textarea> html code in my web site document and want the user to be able to click a button and that way be able to insert a text snippet.

Example:

Maybe the user want to insert a predefined text on the spot in the textarea where the cursor is. What would the code be?

Tricky one...
 
may be something like this...
<HTML><HEAD></HEAD><BODY>
<script>
var string1 = &quot;this is string1&quot;
var string2 = &quot;this is string2&quot;
function ShowString(stringNum)
{
eval(&quot;document.form1.txtSnippet.value=string&quot;+stringNum);
}
</script>

<form name=form1>
<textarea name=&quot;txtSnippet&quot; rows=5 cols=20></textarea>
</form>

<input type=Button onclick=&quot;ShowString(1)&quot; value=&quot;Snippet 1&quot;>
&nbsp;&nbsp;
<input type=Button onclick=&quot;ShowString(2)&quot; value=&quot;Snippet 2&quot;>

</BODY></HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top