...

View Full Version : Manipulating a forms textarea



iambaz
03-04-2005, 07:22 PM
Hi,

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.

dlg0351
03-04-2005, 08:11 PM
Try this:



<html>
<head>
<title></title>

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

<body>

<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>
</form>

</body>
</html>

iambaz
03-06-2005, 01: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?

Vladdy
03-06-2005, 02:02 PM
www.vladdy.net/demos/textareainsertion.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum