The below functions has an issue and I need help please.
First the cursor goes where is should no issue there.
But if I add a bbcode tag where cursor is to nest new tags between tags.
The new tag does not go there, it ends up on the end of all of the tags and I want to like nest them between others.

Example:
[b]Here is what cursor would be and where I would want to add another tag[/b] 
Like so:
[b][i]sometext[/i][/b] which is what I would want.
But it ends up like this:
 which is my issue...
[b]if cursor is here, then I click to add another tag, tag should go here[/b][i]ends up on end[/i

So if anyone can figure this out and put the fix here, you will be the MAN....
Below is short info on page, but should give an idea how it works.


<script language="JavaScript" type="text/javascript">
<!--
var clientInfo = navigator.userAgent.toLowerCase();
var isIE = ( clientInfo.indexOf("msie") != -1 );
var isWin = ( (clientInfo.indexOf("win")!=-1) || (clientInfo.indexOf("16bit") != -1) );

function createBBtag( openerTag , closerTag , areaId ) {
	if(isIE && isWin) {
		createBBtag_IE( openerTag , closerTag , areaId );
	}
	else {
		createBBtag_nav( openerTag , closerTag , areaId );
	}
	return;
}

function createBBtag_IE( openerTag , closerTag , areaId ) {
	var txtArea = document.getElementById( areaId );
	var aSelection = document.selection.createRange().text;
	var range = txtArea.createTextRange();

if(aSelection) {
	document.selection.createRange().text = openerTag + aSelection + closerTag;
	txtArea.focus();
	range.move('textedit');
	range.select();
}
else {
	var oldStringLength = range.text.length + openerTag.length;
	txtArea.value += openerTag + closerTag;
	txtArea.focus();
	range.move('character',oldStringLength);
	range.collapse(false);
	range.select();
}
return;
}

function createBBtag_nav( openerTag , closerTag , areaId ) {
	var txtArea = document.getElementById( areaId );
	if (txtArea.selectionEnd && (txtArea.selectionEnd - txtArea.selectionStart > 0) ) {
		var preString = (txtArea.value).substring(0,txtArea.selectionStart);
		var newString = openerTag + (txtArea.value).substring(txtArea.selectionStart,txtArea.selectionEnd) + closerTag;
		var postString = (txtArea.value).substring(txtArea.selectionEnd);
		txtArea.value = preString + newString + postString;
		txtArea.focus();
	}
	else {
		var offset = txtArea.selectionStart;
		var preString = (txtArea.value).substring(0,offset);
		var newString = openerTag + closerTag;
		var postString = (txtArea.value).substring(offset);
		txtArea.value = preString + newString + postString;
		txtArea.selectionStart = offset + openerTag.length;
		txtArea.selectionEnd = offset + openerTag.length;
		txtArea.focus();
	}
	return;
}
//-->
</script>
                <form name="myForm" action="" method="post" onsubmit="javascript: return checkifvalid();">

<a href="javascript:createBBtag('[p]','[/p]','txtA')" onMouseOver="helpline('p1')"><strong>P</strong></a>
<a href="javascript:createBBtag('[s]','[/s]','txtA')" onMouseOver="helpline('strike1')"><strong>S</strong></a>

            <input type="text" style="color: #FF0000; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #EFF2F5;"name="helpbox" size="90" class="helpbox" readonly="readonly"/>

<form onSubmit="return false;">
	<textarea NAME="myTextArea" ROWS="10" COLS="90" id="txtA"></textarea>
</form>
</form>   

Problem lies in the javascript, needs something for IE

    Here is what is happening if this helps more.

    {p}cursor{/p}
    Click link again and should be like this.
    {b}{s}{/s}{/b}
    Instead it ends up like this.
    {b}{/b}{s}{/s}

    But only in IE

      Write a Reply...