Page 1 of 1

Reset Cursor after inserting bbcode

Posted: Fri Oct 08, 2004 9:46 am
by kendall
I'm trying to build a form similar to this on that i am using to post this message .

I have the following script that inserts the bbcode when a user selects a text

Code: Select all

function storeCaret (textEl) {
       if (textEl.createTextRange) 
         textEl.caretPos = document.selection.createRange().duplicate();
     }

function insertTags(text,opentag,closetag){
		// get text 
		if(text.createTextRange)
			textSelection = document.selection.createRange().text; 
		// insert tags
		if(textSelection)
			document.selection.createRange().text = opentag+textSelection+closetag;
		eval(text).focus();
		theSelection = '';
		return;
		storeCaret(eval(text));
	 }
However i am not getting to reset the cursor at the end of the textarea.value when i

Code: Select all

onClick="insertTags(this.form.aTextArea,'їi]','ї/i]');"


I can't understand why it isnt working

Kendall

Posted: Fri Oct 08, 2004 10:13 am
by feyd
first off, storeCaret will never be called.
second, I don't think you need to eval anything.. you're sending an object in 'text' .. not a string.

Posted: Fri Oct 08, 2004 11:31 am
by kendall
Ok....but no matter where it is i still dont get to reset the cursor to the textarea content Kendall

Posted: Sat Oct 09, 2004 5:42 am
by twigletmac
Out of interest - which browser are you using?

Mac

Posted: Sat Oct 09, 2004 6:46 am
by vigge89
is that code cross-browser compatible?
if you get this to work, I would be more than happy if you could post the code, I need something like this for my CMS :)

Posted: Mon Oct 11, 2004 9:52 am
by kendall
twigle,

Its not cross browser actually but im working on it. Im using it on IE 6

Kendall