Jump to content

Inserting strings into textboxes


Armed Rebel

Recommended Posts

try this, it works in IE and FF

<html><head>	<title>test</title><script type="text/javascript"> function insertText(textareaObj, tag) { 	//IE support 	if (document.selection) 	{   textareaObj.focus();   var sel = document.selection.createRange();   var currentText = sel.text;  sel.text = "["+tag+"]" + currentText + "[/"+tag+"]"; 	} 	//Mozilla/Firefox/Netscape 7+ support 	else if (textareaObj.selectionStart || textareaObj.selectionStart == '0') 	{    var startPos = textareaObj.selectionStart;   var endPos = textareaObj.selectionEnd;   var currentText = textareaObj.value.substring(startPos,endPos);   textareaObj.value = textareaObj.value.substring(0,startPos) + "["+tag+"]" + currentText + "[/"+tag+"]" +        textareaObj.value.substring(endPos,textareaObj.value.length);	} 	else    textareaObj.value += tag;  } </script></head><body>	<textarea id="rte" rows="10" cols="45"></textarea><br/>	<input type="button" value="Insert [b] tags" onclick="insertText(document.getElementById('rte'),'b')"/></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...