View Full Version : Manipulating a forms textarea

03-04-2005, 08:22 PM

I am trying to create a button on my form that when pressed, will add a certain html tag to the beginning and end of the selected string. Same as what is used in this textarea where if you select a certain string and click the above Bold icon, it will put the tags in.

Any help apreciated. Thanks.

03-04-2005, 09:11 PM
Try this:


<script language="Javascript">
function addTag()
var startTag = "<b>";
var endTag = "</b>";
var content = document.myform.content.value;
document.myform.content.value = startTag + content + endTag;


<form name="myform">
<p><textarea name="content" rows="5" cols="35" wrap="virtual"></textarea></p>
<p><input type="button" name="btnAddTag" value="Add Tag" onClick="addTag()"></p>


03-06-2005, 02:42 PM
Thanks for that but doing this encapsulates the whole textarea with the tags and not just the selected text. Is there a way we can add the tags to only the selected text?

03-06-2005, 03:02 PM